课程列表接口,课程详情接口()
Posted yb635238477
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了课程列表接口,课程详情接口()相关的知识,希望对你有一定的参考价值。
先在models中建几张表结构:
from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation # Create your models here. # class CourseType(models.Model): # type_name = models.CharField(verbose_name=‘课程类别‘,max_length=32) # class Course(models.Model): # title = models.CharField(verbose_name=‘课程名称‘,max_length=32) # course_info = models.CharField(verbose_name=‘课程描述‘,max_length=128) # student_num = models.IntegerField() # choice = ((1,‘初级‘),(2,‘中级‘),(3,‘高级‘)) # student_level = models.IntegerField(verbose_name=‘级别‘,choices=choice) # course_price = models.IntegerField() # class CourseDetail(models.Model): # course = models.OneToOneField(to=‘Course‘) # contents = models.CharField(verbose_name=‘所学内容‘,max_length=128) # time = models.CharField(verbose_name=‘时长‘,max_length=32) # choice = ((1, ‘初级‘), (2, ‘中级‘), (3, ‘高级‘)) # student_level = models.IntegerField(verbose_name=‘级别‘, choices=choice) # student_num = models.IntegerField() # score = models.IntegerField() # recommended_courses = models.CharField(verbose_name=‘推荐课程‘,max_length=32) # class Price(models.Model): # old_price = models.IntegerField(verbose_name=‘原价‘) # now_price = models.IntegerField(verbose_name=‘现价‘) # content_type = models.ForeignKey(to=ContentType) # object_id = models.PositiveIntegerField() # content_object = GenericForeignKey("content_type", "object_id") # class CourseChapter(models.Model): # course_detail = models.ForeignKey(to=‘CourseDetail‘) # # class ClassHours(models.Model): # course_chapter = models.OneToOneField(to=‘CourseChapter‘) # # class questions(models.Model): # content_type = models.ForeignKey(to=ContentType) # object_id = models.PositiveIntegerField() # content_object = GenericForeignKey("content_type", "object_id") # class teacher(models.Model): # name = models.CharField(verbose_name=‘姓名‘,max_length=32) # choice = ((1,‘男‘),(2,‘女‘)) # sex = models.IntegerField(verbose_name=‘性别‘,choices=choice) class Course(models.Model): """专题课程""" name = models.CharField(max_length=128, unique=True) course_img = models.CharField(max_length=255) brief = models.TextField(verbose_name="课程概述", max_length=2048) level_choices = ((0, ‘初级‘), (1, ‘中级‘), (2, ‘高级‘)) level = models.SmallIntegerField(choices=level_choices, default=1) pub_date = models.DateField(verbose_name="发布日期", blank=True, null=True) period = models.PositiveIntegerField(verbose_name="建议学习周期(days)", default=7) order = models.IntegerField("课程顺序", help_text="从上一个课程数字往后排") status_choices = ((0, ‘上线‘), (1, ‘下线‘), (2, ‘预上线‘)) status = models.SmallIntegerField(choices=status_choices, default=0) # 用于GenericForeignKey反向查询,不会生成表字段,切勿删除 price_policy = GenericRelation("PricePolicy") def __str__(self): return self.name class Meta: verbose_name_plural = "专题课" class CourseDetail(models.Model): """课程详情页内容""" course = models.OneToOneField("Course", on_delete=models.CASCADE) hours = models.IntegerField("课时") # 课程的标语 口号 course_slogan = models.CharField(max_length=125, blank=True, null=True) # video_brief_link = models.CharField(verbose_name=‘课程介绍‘, max_length=255, blank=True, null=True) # why_study = models.TextField(verbose_name="为什么学习这门课程") # what_to_study_brief = models.TextField(verbose_name="我将学到哪些内容") # career_improvement = models.TextField(verbose_name="此项目如何有助于我的职业生涯") # prerequisite = models.TextField(verbose_name="课程先修要求", max_length=1024) # 推荐课程 recommend_courses = models.ManyToManyField("Course", related_name="recommend_by", blank=True) teachers = models.ManyToManyField("Teacher", verbose_name="课程讲师") def __str__(self): return "%s" % self.course class Meta: verbose_name_plural = "课程详细" class PricePolicy(models.Model): """价格与有课程效期表""" price = models.FloatField() # course = models.ForeignKey("Course") valid_period_choices = ((1, ‘1天‘), (3, ‘3天‘), (7, ‘1周‘), (14, ‘2周‘), (30, ‘1个月‘), (60, ‘2个月‘), (90, ‘3个月‘), (180, ‘6个月‘), (210, ‘12个月‘), (540, ‘18个月‘), (720, ‘24个月‘), ) valid_period = models.SmallIntegerField(choices=valid_period_choices) content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) # 关联course or degree_course object_id = models.PositiveIntegerField() content_object = GenericForeignKey(‘content_type‘, ‘object_id‘) class Meta: unique_together = ("content_type", ‘object_id‘, "valid_period") verbose_name_plural = "价格策略" def __str__(self): return "%s(%s)%s" % (self.content_object, self.get_valid_period_display(), self.price) class Teacher(models.Model): """讲师、导师表""" name = models.CharField(max_length=32) image = models.CharField(max_length=128) brief = models.TextField(max_length=1024) def __str__(self): return self.name class Meta: verbose_name_plural = "讲师"
数据库迁移后录入数据:
前端发送axios请求:
以上是关于课程列表接口,课程详情接口()的主要内容,如果未能解决你的问题,请参考以下文章
FastAPI(七十九)实战开发《在线课程学习系统》接口开发-- 加入课程和退出课程
FastAPI(七十七)实战开发《在线课程学习系统》接口开发-- 课程编辑和查看评论