Answer the question
In order to leave comments, you need to log in
How to organize forms for Django objects bound via ForeignKey?
In general, you need to make it so that the user can enter "question" and "answer options" on the same page, while there should be no restrictions on answer options, I think that there should be ajax in some place, but unfortunately I'm still on my way his study.
Been struggling with this all night and ended up only redirecting to a page with an additional form for adding answer options, but that's not it!
Model code:
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.question_text
class Choice(models.Model):
choice_text = models.CharField(max_length=200)
question = models.ForeignKey(Question, on_delete=models.CASCADE)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question