Beispiel #1
0
class Teacher(models.Model):
    """讲师"""
    # 一个机构会有很多老师,所以我们在讲师表添加外键并把课程机构名称保存下来
    # 可以使我们通过讲师找到对应的机构
    org = models.ForeignKey(CourseOrg, on_delete=models.CASCADE, verbose_name=u"所属机构", help_text=f'{settings.MAIN_DISPLAY}__name')
    name = models.CharField(max_length=50, verbose_name=u"教师名称")
    work_years = models.IntegerField(default=0, verbose_name=u"工作年限")
    work_company = models.CharField(max_length=50, verbose_name=u"就职公司")
    work_position = models.CharField(max_length=50, verbose_name=u"公司职位")
    age = models.IntegerField(default=18, verbose_name=u"年龄")
    points = models.CharField(max_length=50, verbose_name=u"教学特点")
    click_nums = models.IntegerField(default=0, verbose_name=u"点击数")
    fav_nums = models.IntegerField(default=0, verbose_name=u"收藏数")
    image = ImageField(
        default='',
        upload_to="teacher/%Y/%m",
        verbose_name=u"头像",
        max_length=100, help_text=settings.MAIN_AVATAR)
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")

    class Meta:
        verbose_name = u"教师"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "[{0}]的教师: {1}".format(self.org, self.name)
Beispiel #2
0
class Banner(models.Model):
    """轮播图model"""
    title = models.CharField(max_length=100, verbose_name=u"标题")
    image = ImageField(upload_to="banner/%Y/%m",
                       verbose_name=u"轮播图",
                       max_length=100,
                       help_text=settings.MAIN_PIC)
    url = models.URLField(max_length=200, verbose_name=u"访问地址")
    # 默认index很大靠后。想要靠前修改index值。
    index = models.IntegerField(default=100, verbose_name=u"顺序")
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")

    class Meta:
        verbose_name = u"轮播图"
        verbose_name_plural = verbose_name

    # 重载__str__方法使后台不再直接显示object

    def __str__(self):
        return '{0}(位于第{1}位)'.format(self.title, self.index)
Beispiel #3
0
class UserProfile(AbstractUser):
    # 自定义的性别选择规则
    GENDER_CHOICES = (("male", u"男"), ("female", u"女"))
    # 昵称
    nick_name = models.CharField(max_length=50, verbose_name=u"昵称", default="")
    # 生日,可以为空
    birthday = models.DateField(verbose_name=u"生日", null=True, blank=True)
    # 性别 只能男或女,默认女
    gender = models.CharField(max_length=6,
                              verbose_name=u"性别",
                              choices=GENDER_CHOICES,
                              default="female")
    # 地址
    address = models.CharField(max_length=100, verbose_name="地址", default="")
    # 电话
    mobile = models.CharField(max_length=11,
                              null=True,
                              blank=True,
                              verbose_name=u"电话")
    # 头像 默认使用default.png
    image = ImageField(upload_to="image/%Y/%m",
                       default=u"image/default.png",
                       max_length=100,
                       verbose_name=u"头像",
                       help_text=settings.MAIN_AVATAR)

    # meta信息,即后台栏目名
    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    # 重载__str__方法,打印实例会打印username,username为继承自AbstractUser
    def __str__(self):
        return self.username

    # 获取用户未读消息的数量
    def unread_nums(self):
        from operation.models import UserMessage
        return UserMessage.objects.filter(has_read=False, user=self.id).count()
Beispiel #4
0
class Course(models.Model):
    """课程信息表"""
    DEGREE_CHOICES = (("cj", u"初级"), ("zj", u"中级"), ("gj", u"高级"))
    course_org = models.ForeignKey(CourseOrg,
                                   on_delete=models.CASCADE,
                                   verbose_name=u"所属机构",
                                   null=True,
                                   blank=True,
                                   help_text=f'{MAIN_DISPLAY}__name')
    teacher = models.ForeignKey(Teacher,
                                on_delete=models.CASCADE,
                                verbose_name=u"讲师",
                                null=True,
                                blank=True,
                                help_text=f'{MAIN_DISPLAY}__name')
    name = models.CharField(max_length=50, verbose_name=u"课程名")
    desc = models.TextField(max_length=300, verbose_name=u"课程描述")
    # TextField允许我们不输入长度。可以输入到无限大。暂时定义为TextFiled,之后更新为富文本
    # 修改image path,不能传y m 进来,不能加斜杠是一个相对路径,相对于setting中配置的media root
    detail = UEditorField(verbose_name=u"课程详情",
                          width=600,
                          height=300,
                          imagePath="courses/ueditor/",
                          filePath="courses/ueditor/",
                          default='')
    is_banner = models.BooleanField(default=False, verbose_name=u"是否轮播")
    degree = models.CharField(choices=DEGREE_CHOICES,
                              max_length=2,
                              verbose_name=u"难度")
    # 使用分钟做后台记录(存储最小单位)前台转换
    learn_times = models.IntegerField(default=0, verbose_name=u"学习时长(分钟数)")
    # 保存学习人数:点击开始学习才算
    students = models.IntegerField(default=0, verbose_name=u"学习人数")
    fav_nums = models.IntegerField(default=0, verbose_name=u"收藏人数")
    you_need_know = models.CharField(max_length=300,
                                     default=u"一颗勤学的心是本课程必要前提",
                                     verbose_name=u"课程须知")
    teacher_tell = models.CharField(max_length=300,
                                    default=u"什么都可以学到,按时交作业,不然叫家长",
                                    verbose_name=u"老师告诉你")
    image = ImageField(upload_to="courses/%Y/%m",
                       verbose_name=u"封面图",
                       max_length=100,
                       help_text=MAIN_PIC)
    # 保存点击量,点进页面就算
    click_nums = models.IntegerField(default=0, verbose_name=u"点击数")
    category = models.CharField(max_length=20,
                                verbose_name=u"课程类别",
                                default=u"后端开发")
    tag = models.CharField(max_length=15, verbose_name=u"课程标签", default=u"")
    add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")

    class Meta:
        verbose_name = u"课程"
        verbose_name_plural = verbose_name

    # 替代标签:course.lesson_set.count
    # def get_zj_nums(self):
    #     # 获取课程章节数的方法
    #     return self.lesson_set.all().count()

    # 获取学习这门课程的用户
    # 替代标签:course.usercourse_set.get_queryset|slice:":1"
    # def get_learn_users(self):
    #     # 谁的里面添加了它做外键,他都可以取出来
    #     return self.usercourse_set.all()[:5]

    def __str__(self):
        return self.name + self.teacher.name