Sunday, February 23, 2020

Re: get_FOO_display not working ?

Hi

Actually, the human readable value is not ('Draft') but _('Draft') which is shorthand for gettext_lazy('Draft')

Yves


Le 22 févr. 2020 à 23:54, Nde Nguti <nguti.donatus@gmail.com> a écrit :

CHOICES =(('draft', 'Draft'), )

On Sun, Feb 23, 2020, 05:48 Yves de Champlain <yesyves@gmail.com> wrote:
Hi

I'm using StatusModel from models_utils :

class MetaData(TimeStampedModel, StatusModel, SoftDeletableModel):
    STATUS
= Choices(('draft', _('Draft')),
                     
('submitted', _('Submitted')),
                     
('underreview', _('Underreview')),
                     
)

Forms using STATUS work as expected, but when I load an object from the DB, I can't access the human readable data in my templates.

a.status => draft
a
.get_status_display => draft

instead of

a.status => draft
a
.get_status_display => Draft

Thanks for any hep on this !

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d7a06913-39a8-4e55-9799-ebc46cb5cde4%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALfkE84BbTc47u0TGL_PWYNXpoXjs0rsZUG4rjSBNySd8SLGyw%40mail.gmail.com.

No comments:

Post a Comment