Django嵌套内联管理表单问题

时间:2011-08-04 14:28:46

标签: django inline admin

我正在尝试按照this question中的示例,但某些内容对我不起作用。

我正在尝试制作一款管理教育标准的应用。在问题的简化版本中,有三种信息。有主题,如数学。有广泛的标准,如“学生将能够添加数字”。有标准,例如“学生将能够添加一位数字”。我相信我的模型设置正确:

# Subjects, such as math, science, english...
class Subject(models.Model):
    subject = models.CharField(max_length=255, unique=True)

# Broad standards, such as "Students will understand the structure of matter."
class BroadStandard(models.Model):
    broad_standard = models.CharField(max_length=255, unique=True)
    subject = models.ForeignKey(Subject)

# Standards, such as "Students will understand the structure of the periodic table."
class Standard(models.Model):
    standard = models.CharField(max_length=255, unique=True)
    broad_standard = models.ForeignKey(BroadStandard)

我无法设置管理员。我知道我不能嵌入内联。我希望用户能够输入主题,然后输入一个广泛的标准。要输入标准,我希望用户必须点击广泛的标准,然后进入单独的页面输入标准。没关系,但管理页面没有提供输入标准的链接。我的admin.py代码:

class BroadStandardInline(admin.TabularInline):
    model = BroadStandard
    extra = 0

class StandardInline(admin.TabularInline):
    model = Standard
    extra = 0

class BroadStandardAdmin(admin.ModelAdmin):
    inlines = [StandardInline]

class StandardAdmin(admin.ModelAdmin):
    fields = ['standard']

class SubjectAdmin(admin.ModelAdmin):
    fields = ['subject']
    inlines = [BroadStandardInline]

admin.site.register(Subject, SubjectAdmin)

如何以主表格或点击广泛标准显示“标准”字段?

0 个答案:

没有答案