This is clearly described in the polls application tutorial.
https://docs.djangoproject.com/en/2.1/intro/tutorial01/
On Thu 6 Sep, 2018, 9:38 PM Ousseynou Diop, wrote:
> Hi friend ,
>
> use this function to display the choices field.
>
> models.py
>
>
> class Article(models.Model):
>
>
Hi friend ,
use this function to display the choices field.
models.py
class Article(models.Model):
ARTICLE_CHOICES = (
)
status = models.CharField(max_length=120, choices=ARTICLE_CHOICES, )
in your templates
{% article in articles %}
{{artcile.get_status_display}}
{%
you just need to enclose it in a get__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.
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
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 wrote:
On Tue, Feb 10, 2009 at 6:39 PM, Kevin Audleman 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,
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 wrote:
> On Tue, Feb 10, 2009 at 4:23 PM, Kevin Audleman
>
On Tue, Feb 10, 2009 at 4:23 PM, Kevin Audleman 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
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,
9 matches
Mail list logo