im building a survey app or something similar, each question has three or more answer, i cant get it works that in the template, i mean, nest the question with the corresponding answers, this are my models:
class Trivia(models.Model):
nombre = models.CharField(max_length=100)
slug = models.SlugField(unique=True)
categoria = models.ForeignKey(Categorias)
contador = models.IntegerField()
def __str__(self):
return self.nombre
class Meta():
verbose_name_plural = "Trivias"
class Preguntas(models.Model):
trivia = models.ForeignKey(Trivia)
pregunta = models.CharField(max_length=100)
def __str__(self):
return self.pregunta
class Meta():
verbose_name_plural = "Preguntas"
class Respuestas(models.Model):
Pregunta = models.ForeignKey(Preguntas)
respuesta = models.CharField(max_length=100)
def __str__(self):
return self.respuesta
class Meta():
verbose_name_plural = "Respuestas"
and my views:
class TriviaView(ListView):
model = Preguntas
paginate_by = 1
template_name = 'trivias.html'
And this my template:
<p>{% for pregunta in object_list %} {{pregunta.pregunta}} {% endfor %}</p>
How can i nest the question with their corresponding answers?
Sorry for the spanish attributes named, my client asked like that