1.路径表
# 路径表 class Path(Base): title = models.CharField('路径名', max_length=16) img = models.ImageField('路径图片', upload_to='path', null=True) desc = models.CharField('路径描述', max_length=255) user = models.ManyToManyField('user.User', blank=True) def course_total(self): count = 0 for jd in self.jieduan.all(): count = count + jd.courses.count() return count class Meta: db_table = 'tb_path' def __str__(self): return self.title
![](https://img2020.cnblogs.com/blog/1871139/202011/1871139-20201111114505483-618807924.png)
2.阶段表
class JieDuan(Base): title = models.CharField('阶段名', max_length=16) serial_num = models.IntegerField('阶段序号') path = models.ForeignKey(Path, related_name='jieduan', on_delete=models.SET_NULL, null=True) courses = models.ManyToManyField(Course, blank=True) class Meta: db_table = 'tb_jieduan' def __str__(self): return "%s-第%s阶段-%s" % (self.path.title, self.serial_num, self.title)