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)