Answer the question
In order to leave comments, you need to log in
How to add 2 inlines in django admin?
I am new to django and would like to know. Whether it is possible to make somehow that there was a possibility of creation of two inlines? And if not, how can this be done differently, it is desirable that everything can be edited in one table
from django.db import models
# Create your models here.
class Test(models.Model):
title = models.CharField(max_length=4096)
visible = models.BooleanField(default=False)
max_points = models.IntegerField()
category = models.CharField(default="default category", max_length=4096)
def __str__(self):
return self.title
class Question(models.Model):
question = models.ForeignKey(Test, on_delete=models.DO_NOTHING)
question_text = models.TextField()
question_point = models.IntegerField(default = 1)
def __str__(self):
return self.question_text
class Choice(models.Model):
choice = models.ForeignKey(Question, on_delete=models.DO_NOTHING)
choice_text = models.TextField()
choice_point = models.IntegerField(default = 0)
def __str__(self):
return self.choice_text
from django.contrib import admin
from .models import Test, Question, Choice
class QuestionInline(admin.StackedInline):
model = Question
extra = 1
class TestAdmin(admin.ModelAdmin):
list_display = (
'title',
'visible',
'max_points',
'category',
)
inlines = [QuestionInline]
admin.site.register(Test, TestAdmin)
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