代码如下:
Model:
class Person(models.Model):
name = models.CharField(max_length=200)
CATEGORY_CHOICES = (
('M','Male'),
('F','Female'),
)
gender = models.CharField(max_length=200, choices = CATEGORY_CHOICES)
to_be_listed = models.BooleanField(default=True)
description = models.CharField(max_length=20000, blank=True)
views:
def index(request):
latest_person_list2 = Person.objects.filter(to_be_listed=True)
return object_list(request, template_name='polls/schol.html',queryset=latest_person_list, paginate_by=5)
在template里面,如果要获得gender的choices里面的Male和Female,可以使用get_gender_foo(),这个django规定俗称的语法