有人可以解释一下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)
答案 0 :(得分:2)
如果True
的值等于False
或<instance-of-class-student>.year_in_school
JR
或SR
表格更多信息,以下是会员运营商的一些示例:http://www.tutorialspoint.com/python/membership_operators_example.htm