Thursday, June 22, 2017

Re: model choice field

On Thursday, 22 June 2017 09:09:24 UTC+1, shahab emami wrote:
hello

i have a model choice field like this:

LEVEL_CHOICES = [
        ('1', 'one'),
        ('2', 'two'),
        ('3', 'three'),
    ]

but when i select from database and say:

{{object.level}}

 it shows me 1 or 2 or 3 but i wanted to be one or two or three

how can i do that?

i did some search but i got nothing , actually i dont now what i have to search for this problem

thank you

{{ object.get_level_display }}

See the docs for the `choices` argument: https://docs.djangoproject.com/en/1.11/ref/models/fields/#choices
which links to the docs for that  specific syntax: https://docs.djangoproject.com/en/1.11/ref/models/instances/#django.db.models.Model.get_FOO_display
--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a7d90341-e38c-4ac3-a361-73c6a1889012%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment