Django选择教程

时间:2015-02-21 21:03:14

标签: python django python-3.x django-models

有人可以解释一下Django教程中选择示例末尾的函数是什么吗?

谢谢!

from django.db import model

class Student(models.Model):
    FRESHMAN = 'FR'
    SOPHOMORE = 'SO'
    JUNIOR = 'JR'
    SENIOR = 'SR'
    YEAR_IN_SCHOOL_CHOICES = (
        (FRESHMAN, 'Freshman'),
        (SOPHOMORE, 'Sophomore'),
        (JUNIOR, 'Junior'),
        (SENIOR, 'Senior'),
    )
    year_in_school = models.CharField(max_length=2,
        choices=YEAR_IN_SCHOOL_CHOICES, default=FRESHMAN)

    def is_upperclass(self):
        return self.year_in_school in (self.JUNIOR, self.SENIOR)

1 个答案:

答案 0 :(得分:2)

如果True的值等于False<instance-of-class-student>.year_in_school

,则该函数将返回JRSR

表格更多信息,以下是会员运营商的一些示例:http://www.tutorialspoint.com/python/membership_operators_example.htm