get_FOO_display not working ?

153 views
Skip to first unread message

Yves de Champlain

unread,
Feb 22, 2020, 11:47:38 PM2/22/20
to Django users
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 !

Nde Nguti

unread,
Feb 22, 2020, 11:53:59 PM2/22/20
to django...@googlegroups.com
Try
('draft', 'Draft') not ('draft', ('Draft'))




--
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...@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.

Nde Nguti

unread,
Feb 22, 2020, 11:55:25 PM2/22/20
to django...@googlegroups.com
CHOICES =(('draft', 'Draft'), )

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

Mike Dewhirst

unread,
Feb 23, 2020, 2:34:06 AM2/23/20
to django...@googlegroups.com
Maybe the choices should be

STATUS = [
    ('draft', _('Draft')),
    ...
]

I think the migration system might detect a change in the model every time it is run because the get_text_lazy() function can return a non-static result. Not sure about that.

I haven't used _() myself but I have used methods to fill up choices lists with just that outcome. I had to finalize the list prior to running migrate.

Not much help I know

Good luck

Mike
--

Yves de Champlain

unread,
Feb 23, 2020, 2:43:23 PM2/23/20
to django...@googlegroups.com
Hi

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

Yves


Yves de Champlain

unread,
Feb 23, 2020, 2:44:15 PM2/23/20
to django...@googlegroups.com
Hi

I’ll know if it is much help if it solves my problem. I’ll have a look into that.

Thanks !

yves


Reply all
Reply to author
Forward
0 new messages