Answer the question
In order to leave comments, you need to log in
How to correctly display all contests with the data of these contests in a Dajngo template?
I have a contest model, it has a question model, and in the question model, it has a choice model.
models.py
#модель конкурса
class Quest(models.Model):
title = models.CharField(max_length = 500)
def __str__(self):
return self.title
#модель вопросов конкурса
class Questions(models.Model):
title = models.CharField('Название вопроса', max_length=500)
question_above = models.CharField('Ответ', max_length=1000)
quest = models.ForeignKey(Quest, on_delete=models.CASCADE, related_name='questi')
def __str__(self):
return self.title
#модель вариантов ответа вопроса
class Questions_var(models.Model):
question = models.CharField('Вариант ответа', max_length=500)
questions = models.ForeignKey(Questions, on_delete=models.CASCADE, related_name='questions')
class QuestionsInline(nested_admin.NestedStackedInline):
model = Questions_var
extra = 1
@admin.register(Questions)
class QuestionsAdmin(admin.ModelAdmin):
inlines = [QuestionsInline]
class QuestInline(nested_admin.NestedStackedInline):
fk_name = 'quest'
model = Questions
inlines = [QuestionsInline]
extra = 1
@admin.register(Quest)
class QuestAdmin(nested_admin.NestedModelAdmin):
inlines = [QuestInline]
def get_questions(self):
return self.questions_set.all()
Answer the question
In order to leave comments, you need to log in
read until enlightenment
https://docs.djangoproject.com/en/2.2/topics/db/qu...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question