其他分享
首页 > 其他分享> > day35 crm开发之limit_choices_to筛选和前端时间框处理

day35 crm开发之limit_choices_to筛选和前端时间框处理

作者:互联网

django框架中models可以关联表limit_choices_to可进行关联数据筛选

class ClassList(models.Model):
    """
    班级表
    如:
        Python全栈  面授班  5期  10000  2017-11-11  2018-5-11
    """
    school = models.ForeignKey(verbose_name='校区', to='School')
    course = models.ForeignKey(verbose_name='课程名称', to='Course')
    semester = models.PositiveIntegerField(verbose_name="班级(期)")
    price = models.PositiveIntegerField(verbose_name="学费")
    start_date = models.DateField(verbose_name="开班日期")
    graduate_date = models.DateField(verbose_name="结业日期", null=True, blank=True)
    class_teacher = models.ForeignKey(verbose_name='班主任', to='UserInfo', related_name='classes',
                                      limit_choices_to={'depart__title': '教质部'},on_delete=models.CASCADE)
    tech_teachers = models.ManyToManyField(verbose_name='任课老师', to='UserInfo', related_name='teach_classes', blank=True,
                                           limit_choices_to={'depart__title__in': ['Linux教学部', 'Python教学部']})
    memo = models.TextField(verbose_name='说明', blank=True, null=True)

    def __str__(self):
        return "{0}({1}期)".format(self.course.name, self.semester)

标签:__,verbose,models,day35,choices,limit,True,name
来源: https://www.cnblogs.com/simon1993/p/15972253.html