python - Django: Display Choice Value -
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.py:
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)
on template, when call person.gender, 'm' or 'f' instead of 'male' or 'female'. how display value ('male' or 'female') instead of code(m/f)?
it looks on right track - get_foo_display() want:
in templates, don't include () in name of method. following:
{{ person.get_gender_display }}
Comments
Post a Comment