Home:ALL Converter>Importing models to forms in Django

Importing models to forms in Django

Ask Time:2021-02-22T01:22:12         Author:Myrodis

Json Formatter

I am making a quiz web application and I want to create answers to questions from admin panel, not writing a code for each set of answers. How can I do that?

forms:

from django import forms

ANSWER_CHOICES = [
    ('1', 'First'),
    ('2', 'Second'),
    ('3', 'Third'),
]
class AnswerForm(forms.Form):
    answer = forms.ChoiceField(
        label = '',
        required=False,
        widget=forms.RadioSelect,
        choices=ANSWER_CHOICES,
    )

models:

from django.db import models

class Questions(models.Model):
    title = models.CharField('Question', max_length=200)

    def __str__(self):
        return self.title

Author:Myrodis,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/66305016/importing-models-to-forms-in-django
yy