[英]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? 如何在Django管理面板中显示特定模型的子代的表单?
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 references 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.