Icons for datepicker don't show up when `_get_form_class` is executed twice for a single form
vanschelven opened this issue · 4 comments
vanschelven commented
Similar to #21 but with a different cause (in fact: #21's solution might be the cause).
When the filter's _get_form_class
is executed twice in the process of constructing a single form, the required JS is not produced, which leads to
- an error
jQuery.Deferred exception: DateTimeShortcuts is not defined
in the JS console - the icons for the datepicker not showing up.
Code to reproduce:
@admin.register(Foo)
class FooAdmin(models.ModelAdmin):
def get_changelist_instance(self, request):
cl = super().get_changelist_instance(request)
q = cl.get_queryset(request)
return cl
list_filter = [
('bar', DateRangeFilter),
]
The reason you might want to do the above for the curious.
django==2.2.20
django-admin-rangefilter==0.7.0
The workaround for now has been to add request.DJANGO_RANGEFILTER_ADMIN_JS_SET = False
right before the get_queryset
call, but this is less than optimal.
vanschelven commented
Some random thoughts from under the proverbial shower:
- Perhaps moving the "just do it once" check to a point where the form is rendered, rather than just initialized, could be a way forward.
- Since this package is reusing django's date widget, I wonder: the present package can't be the only one suffering from this particular problem, right?
silentsokolov commented
Thx, fixed on 0.8.0 version
vanschelven commented
Awesome, I'll check it out next week!
vanschelven commented
Indeed 0.8.1
fixes the problem I was experiencing, many thanks!