I've 3 models:-
class Category(models.Model):
name = models.CharField(max_length=60)
class CategoryQuestions(models.Model):
# Questions related to category.
question_text = models.CharField(max_length=255)
category = models.ForeignKey(Category)
class CategoryQuestionsOptions(models.Model):
# Options related to each question.
option = models.CharField(max_length=255)
question = models.ForeignKey(CategoryQuestions)
I want that whenever I add a category, I must be able to add N questions and N options to each question.
Here is my admin.py
class CategoryQuestionsInline(admin.StackedInline):
model = CategoryQuestions
extra = 4
class CategoryAdmin(admin.ModelAdmin):
inlines = [CategoryQuestionsInline]
list_display = ('name', 'code', 'description')
search_fields = ['name', 'code']
admin.site.register(Category, CategoryAdmin)
Currently, I;m able to add N questions while creating a new category. How can I create N options for each question while creating a new category on the same page,?
