silentsokolov / django-admin-rangefilter

A Django app that lets you filter data by date range and numeric range in the admin UI
MIT License
721 stars 106 forks source link

Icons for datepicker don't show up when `_get_form_class` is executed twice for a single form #62

Closed vanschelven closed 3 years ago

vanschelven commented 3 years ago

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

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 3 years ago

Some random thoughts from under the proverbial shower:

silentsokolov commented 3 years ago

Thx, fixed on 0.8.0 version

vanschelven commented 3 years ago

Awesome, I'll check it out next week!

vanschelven commented 3 years ago

Indeed 0.8.1 fixes the problem I was experiencing, many thanks!