Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: list_filter using a friendly name

Tags:

python

django

In my admin.py I filter by 'active' and 'country' this is done using the following line of code within my SomethingAdmin class....

 list_filter = ['active', 'countryid']

As you can see countryid is not pretty when displayed in my admin list view, how can I change this to a more friendly name, say just 'Country'?

Thanks.

Update: Below seems to work:

incentiveid = models.ForeignKey(Incentive,verbose_name="Incentive", 
null=True, db_column='incentiveID', blank=True)
like image 986
Prometheus Avatar asked Feb 05 '13 12:02

Prometheus


1 Answers

As Aamir says, if you define labels on your fields in your model, you should see the more attractive filter options:

class MyModel(models.Model):
    countryid = models.ForeignKey(Country, 
                                  verbose_name="Country", null=True, 
                                  db_column='countryID', blank=True)

assuming that Country is name of another Model - this should show up in the Admin filter view.

like image 107
danodonovan Avatar answered Oct 13 '22 11:10

danodonovan