Ok, I'm sure I'm missing something stupidly simple, since nobody else seems to be asking the same question. Either way, the problem's annoying me, so I'll suck up my pride and just ask it. I'm mainly just playing around right now with creating a simple Training/Testing application. For starters, I need to be able to create a quiz type application with 20 some odd multiple choice questions. Hence I basically have 3 models: Quizzes, Questions, and Answers. I want in the admin interface to create a quiz, and inline the quiz and answer elements, but at this point I'm willing to settle for just one almost. The goal is to click "Add Quiz", and be transferred to a page with 20 question fields, with 4 answer fields per each in place. Like I said though, I'll settle for just the 20 questions. Here's what I have currently:
class Quiz(models.Model):
label = models.CharField(blank=true, max_length=50)
class Question(models.Model):
label = models.CharField(blank=true, max_length=50)
quiz = models.ForeignKey(Quiz)
class Answer(models.Model):
label = models.CharField(blank=true, max_length=50)
question = models.ForiegnKey(Question)
class QuestionInline(admin.TabularInline):
model = Question
extra = 20
class QuestionAdmin(admin.ModelAdmin):
inlines = [QuestionInline]
class AnswerInline(admin.TabularInline):
model = Answer
extra = 4
class AnswerAdmin(admin.ModelAdmin):
inlines = [AnswerInline]
class QuizAdmin(admin.ModelAdmin):
inlines = [QuestionInline, AnswerInline]
admin.site.register(Question, QuestionAdmin)
admin.site.register(Answer, AnswerAdmin)
admin.site.register(Quiz, QuizAdmin)
Anyways, I'm just in a prototyping phase, and admittedly a bit of newb still. Currently receive a:
class 'quizzer.quiz.models.Answer'> has no ForeignKey to <class 'quizzer.quiz.models.Quiz'>
when I try to add a quiz. Any thoughts? Is this doable, or am I trying to pull too much out of the Django Admin app? And yes, I know it's proper practice to segregate the admin stuff from the models file.