我正在开发一个内容管理系统,用户可以在其中创建供学生学习的课程。
到目前为止,我的数据库具有课程,课程和幻灯片模型,我想将幻灯片模型连接到测验,HTML或视频:
class Course(models.Model):
company = models.ForeignKey(Company, on_delete=models.CASCADE)
slug = models.SlugField(max_length=40, unique=True)
name = models.CharField(max_length=100)
desc = models.CharField(max_length=1000)
date_created = models.DateTimeField(default=datetime.now, blank=True)
last_updated = models.DateTimeField(default=datetime.now, blank=True)
price = models.DecimalField(max_digits=8, decimal_places=2)
is_visible = models.BooleanField(default=True)
def __str__ (self):
return self.name
class Lesson(models.Model):
course = models.ForeignKey(Course, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
order = models.IntegerField()
def __str__ (self):
return self.name
class Quiz(models.Model):
points = models.IntegerField()
# Link to quiz model
class HTML(models.Model):
content = models.TextField(blank=True)
class Video(models.Model):
media_path = models.CharField(max_length=150)
class Slide(models.Model):
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
title = models.CharField(max_length=100)
slide_type = models.CharField(max_length=100, choices=[("video", "Video"),("image", "Image"), ("text", "Text"), ("quiz", "Quiz")])
notes = models.TextField(blank=True)
last_updated = models.DateTimeField(default=datetime.now, blank=True)
content = models.TextField(blank=True)
reference = models.CharField(max_length=150, blank=True)
def __str__ (self):
return self.title
class QuizQuestions(models.Model):
quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE)
question = models.TextField()
points = models.IntegerField()
现在我的幻灯片模型可能是3种事物之一:
如何设计数据库幻灯片模型,使其可以是视频,HTML或测验的链接?
我的想法是:
如果您有更好的主意,请告诉我,我想要一个可扩展的解决方案,并且愿意接受新主意
答案 0 :(得分:1)
有几种方法可以实现此目的。
GenericForeignKey