Inline Forms in Django 1.1 Admin Panel
How do you display forms for the children of a specific model in the Django Admin Panel?
class Matchup(models.Model):
name = models.CharField(max_length=30)
winner = models.ForeignKey('players.player',blank=True)
class Slot(models.Model):
player = models.ForeignKey('players.player',blank=True)
matchup = models.ForeignKey(Matchup)
Each matchup will have two slots - how would I go about displaying forms for both of them in line with the Match.
Basically, I want to have something like this:
Matchup Name: [ ]
Matchup Winner: [ ]
--
== Slot 1 ==
|| Slot Player: [ ]
== Slot 2 ==
|| Slot Player: [ ]
I realize it may appear that the slot model is useless and should just be replaced by two r开发者_开发技巧eferences to players, but there are various reasons I want to do it this way.
EDIT: removed confusing associations
from models import *
class SlotInline(admin.StackedInline):
model = Slot
class MatchupAdmin(admin.ModelAdmin):
model = Matchup
inlines = [SlotInline]
admin.site.register(Matchup, MatchupAdmin)
精彩评论