我有这样的django模型。
model.py
class Event(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class Location(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class Occurrence(models.Model):
event = models.ForeignKey(Event)
location = models.ForeignKey(Location)
class TimeSlot(models.Model):
occurrence = models.ForeignKey(Occurrence)
start = models.DateTimeField()
end = models.DateTimeField()
admin.py
class TimeSlotInline(admin.StackedInline):
model = TimeSlot
extra = 1
class OccurrenceInline(admin.StackedInline):
model = Occurrence
inlines = [TimeSlotInline,]
extra = 2
class EventAdmin(admin.ModelAdmin):
inlines = [OccurrenceInline,]
admin.site.register(Event, EventAdmin)
admin.site.register(Location)
我想在管理页面的一个页面中显示所有字段。(添加新记录时。) 多个内联不起作用。(只有第一个内联。) 还有其他办法吗?
更新:我可以通过修改admin.py文件来完成此操作。我可以将自定义表单添加到admin.py的内联中吗?
答案 0 :(得分:1)
答案 1 :(得分:0)
应该是:
class OccurrenceInline(admin.StackedInline):
model = Occurrence
extra = 2
class EventAdmin(admin.ModelAdmin):
inlines = [OccurrenceInline, TimeSlotInline,]