I'm creating a small site to register sporting event results. I have two following models:
- Team
- Player (of a team)
- Match
- Goals (scored by a Player on a Match)
in more detail:
class Team(models.Model):
name = models.CharField(max_length=255)
class Player(models.Model):
team = models.ForeignKey(Team)
name = models.CharField(max_length=255)
total_goals = models.IntegerField(default=0)
def __unicode__(self):
return u"%s (%s)" % (self.name, self.team)
class Match(TimeStampedModel):
competition = models.ForeignKey(Competition)
league = models.ForeignKey(League, null=True, blank=True) # null==True, ha osztalyozo
home = models.ForeignKey(Team, related_name="merkozes_home")
away = models.ForeignKey(Team, related_name="merkozes_away")
home_score = models.SmallIntegerField(blank=True, null=True)
away_score = models.SmallIntegerField(blank=True, null=True)
goal_list = models.ManyToManyField(Player, through='Goal')
@property
def winner(self):
return self.home if self.home_score > self.away_score else self.away
@property
def loser(self):
return self.home if self.home_score < self.away_score else self.away
class Meta:
unique_together = (('league', 'home', 'away'),)
def __unicode__(self):
return u"%s - %s (%s)" % (self.home, self.away, self.competition)
class Goal(TimeStampedModel):
player = models.ForeignKey(Player)
,atch = models.ForeignKey(Match)
goals = models.SmallIntegerField(default=0)
self_goal = models.BooleanField(default=False, blank=True)
I would like to edit goals together with match details under the django admin. Thus I've created the following admin models:
class GoalsInline(admin.TabularInline):
model = Goal
extra = 1
@admin.register(Match)
class MerkozesAdmin(admin.ModelAdmin):
inlines = [GoalsInline]
Strangely, my admin inline does not show the player
fields, just the other fields from the Goal
model. I checked the html code too, and it's not even a hidden field.
Do you have any idea what might be the reason for this and how can I get all the fields be shown?