[Fixed]-Customizing admin of django to have dependent select fields

16👍

You probably want to use the feature Grouped Selects in django smart selects. From the README:

If you have the following model:

class Location(models.Model)
    continent = models.ForeignKey(Continent)
    country = models.ForeignKey(Country)

And you want that all countries are grouped by the Continent and that Groups are used in the select change to the following:

from smart_selects.db_fields import GroupedForeignKey

class Location(models.Model)
    continent = models.ForeignKey(Continent)
    country = GroupedForeignKey(Country, "continent")

0👍

There is indeed good documentation on how to customize the django admin. Here for example, you can see how to redefine the admin templates.

In the case you present, though, the easier approach as you suggest is to add some JavaScript code that adds the fields extra behavior. You can point the js file with that code in the model’s admin, as explained here.

Leave a comment