我们说我有以下型号
class Owner(models.Model):
name = models.CharField(max_length=255)
class Store(models.Model):
owner = models.OneToOneField(Owner)
class OpeningHours(models.Model):
store = models.ForeignKey(Store)
weekday = models.IntegerField(
choices=WEEKDAYS
)
from_hour = models.TimeField()
to_hours = models.TimeField()
我怎样才能将所有这些模型放在同一个管理页面上? 现在,我只是像所有者一样在所有者模型中内联商店
class StoreInline(models.StackedInline):
model = Store
class OwnerAdmin(models.ModelAdmin):
model = Owner
inlines = (StoreInline,)
但是想做这样的事情
class StoreInline(models.StackedInline):
model = Store
class OpeningHoursInline(models.StackedInline):
model = OpeningHours
class OwnerAdmin(models.ModelAdmin):
model = Owner
# Here, in a perfect world, Django would follow the OneToOneField.
inlines = (StoreInline, OpeningHoursInline, )
我尝试使用带有两个不同库的嵌套内联,但显示有些破碎。由于它是一对一的关系,我确信这是一个微不足道的解决方案。
谢谢!