A
A
AlexVoitenko2015-01-28 17:33:32
Django
AlexVoitenko, 2015-01-28 17:33:32

How, when selecting in one select field, filter the values ​​of another in Django admin?

There are several related models, here is an example:

class League(models.Model):
    name = models.CharField(max_length=50)
    ...

class Team(models.Model):
    name = models.CharField(max_length=50)
    league = models.ForeignKey(League)
    ...

class Player(models.Model):
    league = models.ForeignKey(League, blank=True, null=True)
    team = models.ForeignKey(Team, blank=True, null=True)
    ...

Each league includes 16-20 teams. How, on the Player form page in the admin panel, when choosing league in the team field, only teams from the selected league were available?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rostislav Grigoriev, 2015-01-28
@AlexVoitenko

django-admin-flexselect
Demo video

S
Salavat Sharapov, 2015-01-28
@desperadik

https://docs.djangoproject.com/en/1.7/ref/contrib/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question