I have multiple models :
class Game(models.Model):
name = models.CharField('Nom du jeu', max_length=100)
logo = models.ImageField('Logo', blank=True, upload_to='game_logos')
class League(models.Model):
game = models.ForeignKey(Game, verbose_name='Jeu', null=True, on_delete=models.SET_NULL)
league = models.CharField('Ligue', max_length=20)
hexcolor = models.CharField('Code couleur Hex', max_length=7, blank=True, default='#000000')
class Event(models.Model):
game = models.ForeignKey(Game, verbose_name='Nom du jeu', null=True, on_delete=models.SET_NULL)
event_type = models.CharField(verbose_name="Type d'événement", max_length=50, choices=type_course)
league = models.ForeignKey(League, verbose_name='Ligue', null=True, on_delete=models.SET_NULL)
circuit = models.ForeignKey(Circuit, verbose_name='Circuit', null=True, on_delete=models.SET_NULL)
event_date = models.DateTimeField(verbose_name="Date de la course")
The logic here is, that we have races, that take place place in a certain game, and in a certain league. The thing is, I can have different games that have their own league, independent from the league of the other games (Formula 1 will have League A, B and C, and another game will have League 1, 2 and 3).
So when I set up a new event, as soon as I choose the game, I want to get the leagues associated with this game, not all of them. How can I filter the choices of the leagues based on the game input ?