Я использую django, чтобы сделать множественный выбор. Что у меня есть:
Модель для раздела:
class Section(models.Model):
section_type = models.CharField(max_length=100, choices=section_choices)
text = models.TextField()
equestions = models.ManyToManyField(Question)
class Meta:
app_label = "myapp"
db_table = "section"
managed = True
Модель для вопроса (где я храню все вопросы, которые я задал):
class Question(models.Model):
question_text = models.TextField()
question_type = models.CharField(choices=question_type_choices,
max_length=30)
# MCQ Fields
choice_1 = models.CharField(max_length=20, blank=True, null=True)
choice_2 = models.CharField(max_length=20, blank=True, null=True)
choice_3 = models.CharField(max_length=20, blank=True, null=True)
choice_4 = models.CharField(max_length=20, blank=True, null=True)
correct_answer = models.CharField(max_length=20, blank=True, null=True)
users_answer = models.CharField(max_length=20, blank=True, null=True)
marks = models.PositiveSmallIntegerField(default=2)
class Meta:
app_label = "myapp"
db_table = "question"
managed = True
Как вы видите, у вопроса есть 4 варианта, и они присутствуют в choice_1, choice_2, choice_3 choice_4. Мне нужна форма модели, где я могу отобразить один целый раздел на странице с помощью переключателя и отметить ответы на все вопросы одним кнопка отправки. Возможно ли это с помощью форм и без использования слишком большого числа javascript с этими моделями?