Linked lists in Django Admin and Foreign key model

226 views Asked by At

I have some chained foreign key relationships like this:

class Continent(models.Model):
    continent = models.CharField(max_length=30)

class Country(models.Model):
    country = models.CharField(max_length=30)
    continent = models.ForeignKey(Continent)

class City(models.Model):
    city = models.CharField(max_length=30)
    country = models.ForeignKey(Country)

class Person(models.Model):
    name = models.CharField(max_length=30)
    continent = models.ForeignKey(Continent)
    country = models.ForeignKey(Country)
    city = models.ForeignKey(City)

Is it strictly necessary to have continent and country fields into Person class to make chained select work? I would like that Person model stores only city foreign key, but in admin edit form I would like to show continent/country/city chained select.

0

There are 0 answers