0

好的,所以我有一个看起来像这样的模型:

class OpHour( models.Model ):
    days_of_the_week =((0,"Sunday"),
                   (1,"Monday"),
                   (2,"Tuesday"),
                   (3,"Wednesday"),
                   (4,"Thursday"),
                   (5,"Friday"),
                   (6,"Saturday"))
    day = models.IntegerField(max_length=1, choices=days_of_the_week)
    opening_time = models.TimeField()
    closing_time = models.TimeField()

class Location( models.Model ):
    name = models.CharField(max_length=200)
    [...]
    hours = models.ManyToManyField(OpHour)

我想在位置的更改页面中将 OpHour 显示和编辑为内联。如何使用 ModelAdmin 实现这一目标?

4

1 回答 1

1

只是想在此处复制并粘贴文档的相关部分。@Paulo 发布了一个链接,但您应该专门查看文档"through"中的

from django.contrib import admin

class MembershipInline(admin.TabularInline):
    model = Group.members.through

class PersonAdmin(admin.ModelAdmin):
    inlines = [
        MembershipInline,
    ]

class GroupAdmin(admin.ModelAdmin):
    inlines = [
        MembershipInline,
    ]
    exclude = ('members',)
于 2013-07-16T16:51:21.887 回答