[Django]-How to customize a filter's name displayed in admin site in Django?

5👍

As per my debugging i found that /python2.7/dist-packages/django/contrib/admin/templates/admin/filter.html is the template which is responsible to render filter related content .
in this template you can found

{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}

Here each and every filter’s title is coming from filter_title
so to get the value of filter_title you can go to
/python2.7/dist-packages/django/contrib/admin/filters.py
Here in FieldListFilter class you can see it is directly putting verbose_name into filter.title.
Here you have

list_filter = ['status', 'species__name', 'factor__name', 'factor__type', ]

you can solve your problem by simply providing verbose name to fields which belong to other table and connected into your model as Foreignkey .

#Home  here home is first model
name = models.CharField(verbose_name="Home status", --)
# Out  here Out is second model 
name = models.CharField(verbose_name="out status", ---)
#Main this is main model
home = models.ForeignKey(Home)
out = models.ForeignKey(Out)

so now if you will use filter it will display filter title as Home status and out status

Leave a comment