class CourseCategory(models.Model):
course = models.ForeignKey('Course', on_delete=models.CASCADE)
course_category = models.CharField(max_length=50, unique=True)
lecture_title = models.CharField(max_length=50)
content = models.TextField()
link = models.URLField(blank=True)
def file_size(self, value):
limit = 2 * 1024 * 1024
if value.size > limit:
raise ValidationError('File too large. Size should not exceed 2 MiB.')
file = models.FileField(blank=True, validators=[file_size])
def __str__(self):
return self.category_name
class Meta:
verbose_name = "Course Category"
verbose_name_plural = 'Course Categories'
我希望每次创建一个新的course_category时,我都可以将讲座,内容,链接和文件更多次添加到同一个course_category中。我应该制作一个新模型吗?有更简单的方法吗?