有4张表:
成都创新互联-专业网站定制、快速模板网站建设、高性价比藤县网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式藤县网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖藤县地区。费用合理售后完善,十多年实体公司更值得信赖。Direction(技术方向标),Classification(技术分类表),Level(难度级别表),Video(视频表)
它们的关系是:
Direction与Classification多对多关系
Video与Classification,Level是一对多关系
最终要实现的结果如下图:
二.models代码class Direction(models.Model): """ 技术方向:自动化,测试,运维,前端 """ name = models.CharField(verbose_name='名称', max_length=32) classification = models.ManyToManyField('Classification') class Meta: # 重命名表名,不要自动添加的app名 db_table = 'Direction' verbose_name_plural = '方向(视频方向)' def __str__(self): return self.name class Classification(models.Model): """ 分类:Python Linux JavaScript OpenStack Node.js GO """ name = models.CharField(verbose_name='名称', max_length=32) class Meta: db_table = 'Classification' verbose_name_plural = '分类(视频分类)' def __str__(self): return self.name class Level(models.Model): title = models.CharField(max_length=32) class Meta: db_table = 'Level' verbose_name_plural = '难度级别' def __str__(self): return self.title class Video(models.Model): status_choice = ( (1, '下线'), (2, '上线'), ) status = models.IntegerField(verbose_name='状态', choices=status_choice, default=1) level = models.ForeignKey(Level) classification = models.ForeignKey('Classification', null=True, blank=True) weight = models.IntegerField(verbose_name='权重(按从大到小排列)', default=0) title = models.CharField(verbose_name='标题', max_length=32) summary = models.CharField(verbose_name='简介', max_length=32) # img = models.ImageField(verbose_name='图片', upload_to='./static/images/Video/') img = models.CharField(verbose_name='图片', max_length=32) href = models.CharField(verbose_name='视频地址', max_length=256) create_date = models.DateTimeField(auto_now_add=True) class Meta: db_table = 'Video' verbose_name_plural = '视频' def __str__(self): return self.title