Django-选举年度课程

时间:2018-07-17 21:54:51

标签: python django django-models

选择课程时,我想选择显示该课程所属的年份(例如2011-2012、2012-2013、2014-2015)。

我希望它是自动计算的,而不是手工编写此选择字段。

YEAR = (
    (2011-2012, _(2011 - 2012)),
    (2012-2013, _(2012 - 2013)),
    (2013-2013, _(2013 - 2014)),
)

models.py

class Lesson(models.Model):
    department = models.ForeignKey(Department,on_delete=models.CASCADE)
    academician = models.ManyToManyField(Academician)
    l_code = models.CharField(verbose_name=_('Ders Kodu'), max_length=7)
    l_name = models.CharField(verbose_name=_('Ders Adı'), max_length=45)
    e_year = models.CharField(verbose_name=_('Eğitim Yılı'), max_length=50,)

    def __str__(self):
        academician = '-'.join(
            [str(academician.a_fullname) for academician i self.academician.all()])
        return '{department} - {academician} - {l_code}'.format(department=self.department.d_name,
            academician=academician,l_code=self.l_code)

此选择字段将在admin.py中输入

0 个答案:

没有答案