1
Help me please. I’m learning Django.
I have a website that registers games from my hometown. It follows example to understand doubt:
Championship: Vacation 2017
Has 2 groups (Group 1 and Group 2)
I registered 6 times(São Paulo, Barcelona, Palmeiras, etc ...)
In group 1 are the teams: Arsenal, Botagogo, and Cruise
In group 2 there are the teams: Palmeiras, Real Madrid and São Paulo
My question is: When I select group 1, it lists only teams in group 1 to "play each other" by Django Admin
See in the photo below, first select the group (in the case group 1).
In the list of teams, comes all teams, even the group 2
follows sources:
admin.py
class JogoAdmin(admin.ModelAdmin):
fields = ('grupo', 'data_jogo', 'estadio', 'clube_casa', 'clube_visitante', 'gols_casa', 'gols_visitante', 'jogo_realizado', )
model.py
class Jogo(models.Model):
grupo = models.ForeignKey(Grupo, on_delete=models.CASCADE, related_name='jogo_grupo')
data_jogo = models.DateTimeField()
estadio = models.ForeignKey(Estadio, on_delete=models.PROTECT, related_name='jogo_estadio')
clube_casa = models.ForeignKey(Clube, related_name="jogo_clubecasa", on_delete=models.PROTECT)
clube_visitante = models.ForeignKey(Clube, related_name="jogo_clubevisitante", on_delete=models.PROTECT)
gols_casa = models.IntegerField(default=0)
gols_visitante = models.IntegerField(default=0)
jogo_realizado = models.BooleanField(default=False)
data_cadastro = models.DateTimeField(auto_now_add=True)
class GrupoClube(models.Model):
# Aqui é onde cadastro os times nos grupos
grupo = models.ForeignKey(Grupo, on_delete=models.CASCADE, related_name='grupoclube_grupo')
clube = models.ForeignKey(Clube, on_delete=models.CASCADE, related_name='grupoclube_clube')
data_cadastro = models.DateTimeField(auto_now_add=True)
complete source in: https://github.com/leonardocintra/campeonato
I’m sorry to tell you that with the admin you won’t be able to do this automatically, so it’s best to produce your own input screen. By the way, Admin is not recommended for this type of "input".
– Sidon
That’s what I imagined! Thank you very much!
– Leonardo Nascimento Cintra