Answer the question
In order to leave comments, you need to log in
How to merge Forms from different models in Django admin?
Hello! I'm new to django, I'm sorry not to judge strictly, just help a newbie in learning pliz.
I want to create a database for tests (Subjects, questions, answers). 3 models are interconnected. here is the models.py code:
from django.db import models
# Модель Предметов
class Subject(models.Model):
subject_name = models.CharField("Название предмета:", max_length=100)
LEVEL_CHOICES = (
("1", "1"),
("2", "2"),
("3", "3"),
)
level = models.CharField(
"Уровень предмета:",
max_length = 20,
choices = LEVEL_CHOICES,
default = '1'
)
def __str__(self):
return self.subject_name
class Meta:
verbose_name = "Предмет"
verbose_name_plural = "Предметы"
# Модель Вопросов
class Question(models.Model):
subject_id = models.ForeignKey(Subject, verbose_name='Предмет', on_delete=models.CASCADE)
question = models.TextField("Вопрос")
def __str__(self):
return self.question
class Meta:
verbose_name = "Вопрос"
verbose_name_plural = "Вопросы"
# Модель Ответов
class Answer(models.Model):
question_id = models.ForeignKey(Question, verbose_name='Вопрос', on_delete=models.CASCADE)
answer = models.TextField("Ответ")
correct_answer = (
("0", "Нет"),
("1", "Да"),
)
level = models.CharField(
"Правильный ответ:",
max_length = 1,
choices = correct_answer,
default = '0'
)
def __str__(self):
return self.answer
class Meta:
verbose_name = "Ответ"
verbose_name_plural = "Ответы"
from django.contrib import admin
from .models import Subject, Question, Answer
admin.site.register(Subject)
admin.site.register(Question)
admin.site.register(Answer)
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