you just need to enclose it in a get_<attribute name>_display and it will display it in the template file.
in your example below, you will need to show it as follows in your templates html file: object.get_state_display where object is whatever the object name you have passed via the view. Hope this helps. V. On Tue, Nov 26, 2013 at 1:36 PM, Aniket Zamwar <[email protected]>wrote: > This function gets for a specific information stored in the instance of > the model. > If I want to display as a drop down in the template all the human readable > names in the choices can I do that ? > > Also, Before storing it to DB, how to convert it back to human redable to > short version mentioned in CHOICES used to store in DB ? > > On Wednesday, February 11, 2009 9:13:01 AM UTC-8, Kevin Audleman wrote: >> >> I could've swore I tried that before posting my question and it didn't >> work, but I tried it this time and it did. Anyhow, a long winded way >> of apologizing for asking a simple question. Thank you for taking the >> time to answer! >> >> Kevin >> >> On Feb 10, 3:41 pm, Alex Gaynor <[email protected]> wrote: >> > On Tue, Feb 10, 2009 at 6:39 PM, Kevin Audleman < >> [email protected]>wrote: >> > >> > >> > >> > >> > >> > > Thanks Alex, however this is a solution at the View level, and I'm >> > > using a view that I didn't write. Is there also a way to do this at >> > > the template level? >> > >> > > Thanks again, >> > > Kevin >> > >> > > On Feb 10, 1:24 pm, Alex Gaynor <[email protected]> wrote: >> > > > On Tue, Feb 10, 2009 at 4:23 PM, Kevin Audleman < >> > > [email protected]>wrote: >> > >> > > > > Hi everyone, >> > >> > > > > I've set up a model that has a state field with the input set to >> a >> > > > > list of states, >> > >> > > > > state = models.CharField(max_length=100, blank=True, >> > > > > choices=US_STATE_LIST) >> > >> > > > > The drop-down on the edit form works great, displaying 'Alabama' >> and >> > > > > storing AL in the database. However when I view it, I see AL. How >> do I >> > > > > get django to display the human readable name? >> > >> > > > > I would prefer to do this on the template level, as I'm using a >> view >> > > > > from a contributed app that I can't modify. >> > >> > > > > Thanks, >> > > > > Kevin >> > >> > > >http://docs.djangoproject.com/en/dev/ref/models/ >> instances/?from=olddo.<http://www.google.com/url?q=http%3A%2F%2Fdocs.djangoproject.com%2Fen%2Fdev%2Fref%2Fmodels%2Finstances%2F%3Ffrom%3Dolddo.&sa=D&sntz=1&usg=AFQjCNHPj-y89iTqeSTn2qSjZxQKNgix4g>.. >> >> > >> > > > Alex >> > >> > > > -- >> > > > "I disapprove of what you say, but I will defend to the death your >> right >> > > to >> > > > say it." --Voltaire >> > > > "The people's good is the highest law."--Cicero >> > >> > Yes, the same thing works {{ model.get_FIELD_display }}. >> > >> > Alex >> > >> > -- >> > "I disapprove of what you say, but I will defend to the death your >> right to >> > say it." --Voltaire >> > "The people's good is the highest law."--Cicero > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/13ff53a8-b905-401c-80ae-87da07f79c90%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. > -- Simplicity is the ultimate sophistication. - Leonardo da Vinci Life is really simple, but we insist on making it complicated. - Confucius -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPiONw%3DERGQBK_vgSaSBYttKLEB_kcrWfA0M%3DA9AXMEOx0y7ig%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.

