[Fixed]-Custom SimpleListFilter Subclass for DjangoAdmin

1👍

You need two list_filters, one for the maximal date and one for the minimum date. Query your entries for all distinct years. Something like this:

class MaxDateListFilter(SimpleListFilter):
    title = _('maximum date')
    parameter_name = 'max_date'

    def lookups(self, request, model_admin):
        return [(str(year.year), year.year) \
                 for year in Entry.objects.dates('pub_date', 'year')]

    def queryset(self, request, queryset):
        return queryset.filter(pub_date__year__lte=self.value())

Note: Untested code.

This will work for small ranges. But can be unpractical with bigger datasets.

An alternative is to provide your own ModelAdmin.get_search_results and make it accept some date search queries. Once you have that, you need to render your own ModelAdmin.changelist_view. Add a form to the context and customise the change list template to render this form. Submitting the form should produce the correct search GET request.

Leave a comment