Django nested inline admin form question
I am trying to follow the example in this question, but something is not working for me.
I am trying to make an app that manages educational standards. In the simplified version of the problem, there are three kinds of information. There are Subjects, such as Math. There are Broad Standards such as "Students will be able to add numbers." There are Standards, such as "Students will be able to add one-digit numbers." I believe I have the model set up correctly:
# 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)
I am having trouble setting up the admin. I know I can not nest the inlines. I want the user to be able to enter a subject, and then enter a broad standard. To enter a standard, I expect the user would have to click on the broad standard, and be brought to a separate page to enter the standard. That is fine, but the admin page does not offer a link to enter the standard. My admin.py code:
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(a开发者_如何学编程dmin.ModelAdmin):
fields = ['subject']
inlines = [BroadStandardInline]
admin.site.register(Subject, SubjectAdmin)
How can I make the 'standard' field show up, either in the main form or by clicking on the broad standard?
精彩评论