0
from django.db import models


class Questions(models.Model):
    question = models.CharField(max_length=50)
    choice1 = models.CharField("Choice1", max_length=50,default="option1")
    choice2 = models.CharField("Choice2", max_length=50,default="option2")
    choice3 = models.CharField("Choice3", max_length=50,default="option3")
    choice4 = models.CharField("Choice4", max_length=50,default="option4")
    choice = models.CharField("Choice", max_length=50,default="correct option")

def __str__(self):
        return self.question

This is a modal for creating a question and its options.

now I want to show all four option with question. when i write

Questions.objects.all()

then I only get a question only now how do i get options with the question.

Nep_tune
  • 11
  • 1
  • 5

1 Answers1

0
from django.db import models

answers = [
    ("answer_1", "Answer 1 Label"),
    ("answer_1", "Answer 2 Label"),
    # ...
]

class Questions(models.Model):
    question = models.CharField(max_length=50)
    answer = models.CharField(max_length=50, choices=answers, default="answer_1")

    def __str__(self):
        return self.question
Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177