Answer the question
In order to leave comments, you need to log in
How to create objects in the admin panel?
Hello,
from django.db import models
class Test(models.Model):
title = models.CharField(max_length=150, verbose_name="Test title")
topic = models.ForeignKey("Topic", on_delete=models.PROTECT, null=True, verbose_name="topic")
def __str__(self):
return self.title
class Meta:
verbose_name = "Test"
verbose_name_plural = "Tests"
class Topic(models.Model):
title = models.CharField(max_length=150, verbose_name="Topic title")
def __str__(self):
return self.title
class Meta:
verbose_name = "Topic"
verbose_name_plural = "Topics"
class Question(models.Model):
text = models.TextField(verbose_name="Test name")
photo = models.ImageField(upload_to='photos/%Y/%m/%d/', verbose_name="photo", blank=True)
test = models.ForeignKey(Test, on_delete=models.PROTECT, null=True, verbose_name="test")
class Meta:
verbose_name = "Question"
verbose_name_plural = "Questions"
class Answer(models.Model):
text = models.TextField(verbose_name="Answer text")
is_correct = models.BooleanField(verbose_name="Is correct answer")
question = models.ForeignKey(Question, on_delete=models.PROTECT, null=True, verbose_name="test")
class Meta:
verbose_name = "Answer"
verbose_name_plural = "Answers"
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