I am new to Django and I am struggling to develop the following. I have a survey app in which an admin user can provide to create a new survey template a CSV with a variable number of questions and answers per question, which may be True or False indistinctly.
This is stored using these three different models:
class Survey(models.Model):
survey_name = models.CharField(max_length=50, unique=True)
answer_key = models.CharField(max_length=250)
score_key = models.CharField(max_length=250)
date = models.DateTimeField(auto_now_add=True)
class Question(models.Model):
survey = models.ForeignKey(Survey, on_delete=models.CASCADE)
text = models.CharField(max_length=250)
class Answer(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
text = models.CharField(max_length=250)
valid = models.BooleanField(default=False)
I know how to retrieve the associated objects for a given survey in a view and show them a template, but not how to represent them in a form, since the number of questions and answers per question are not known beforehand. Also not sure how this would be read when processing the POST.
Any hint would be much appreciated.
Thanks!