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

Change Field Title #38

Closed Gilbishkosma closed 5 years ago

Gilbishkosma commented 5 years ago

How should i change the title of date field in filter ? If i don't use the DateRangeFilter then i can easily pass a title for the field . for ex: (('date','Todays Date'),) ,but now i am using DateRangeFilter. Is there any way i can change the tilte?

silentsokolov commented 5 years ago

Is there any way i can change the tilte?

The title is name a model's field. If you need other the title override the template rangefilter/templates/rangefilter/date_filter.html. Or override a filter like in this answer


then i can easily pass a title for the field . for ex: (('date','Todays Date'),)

I don't know, but it doesn't work.

Django 2.2

admin.py

list_filter = (
   ('created_at', 'Cool custom name'),
)

Out:

ERRORS:
<class 'simple.admin.PostAdmin'>: (admin.E115) The value of 'list_filter[0][1]' must inherit from 'FieldListFilter'.
iMakedonsky commented 4 years ago

Easier workaround for this issue:

    list_filter = (
        ('rooms__occupancies__start', DateRangeFilter),
    )

    def get_changelist_instance(self, request):
        instance = super().get_changelist_instance(request)
        instance.filter_specs[0].title = 'occupancy date'
        return instance
vaishakhahk commented 3 years ago

how to replace the title with the selected dates after submission?

silentsokolov commented 3 years ago

@vaishakhahk you have 2 ways: either override the rangefilter's logic or override the template with use jQuery for replace the title (depending on url's path)