我有一个'测试'(:a.k.a考试)模型,可以包含不确定数量的问题。
我希望能够直接在Django的Admin部分创建这些测试
我该怎么办?
我是否必须从头编程逻辑或Django已经考虑过这种情况?
class Question(models.Model):
question = models.CharField()
answer_a = models.Boolean()
solution_a = models.Boolean()
...
class Test(models.Model):
name = models.CharField()
...
class TestQuestion(models.Model):
"""connect many questions to a test"""
test_fk = models.ForeignKey(Test)
question_fk = models.ForeignKey(Question)
[编辑:解决方案]
Django教程非常好地解释了如何执行此操作Part 07
# Admin.py
class QuestionsOfTestInline(admin.StackedInline):
model = QuestionsOfTest
extra = 3
class Test_Admin(admin.ModelAdmin):
inlines = [QuestionsOfTestInline]
admin.site.register(Test, Test_Admin)