[Django]-Django/Python: How to cast an integer into the equivalent enum string?

5👍

Yes, according to the documentation you can get the human readable value like this:

context.get_priority_display()

-2👍

The value on the left is the value Django uses to store in the db. It doesn’t have to be an integer. Just make both values identical:

PRIORITY = (
        ('high',     _(u'High')),
        ('Medium',   _(u'Medium')),
        ('Low',      _(u'Low')),
    )
👤TheOne

Leave a comment