If you want the string instead of the value, you just use:
entity.get_gender_display()
entity.get_gender_display()
Django automatically adds these "magic methods" when you have fields that have choices.
You can see this in the documentation:
Regards,
Andréas
I have in mymodel.py:class GendersChoices(models.IntegerChoices):
M = 0, _('Male')
F = 1, _('Female')
N = 2, _('Gender Neutral')class Address(models.Model):gender = models.PositiveSmallIntegerField(choices=GendersChoices.choices, blank=True, default=GendersChoices.F, null=True,verbose_name=_('Gender'))Now i have a entity from Address and when i make entity.gender i get a number from database. But i want when in entity are insert 2 then i want to get _('Gender Neutral') instead of 2How i can do that?--
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/53c122e7-0448-4d67-9cd4-ce11ffa2ef5cn%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/CAK4qSCcCrg-VtCdJDFRicqY0WpvNw28SMRR3tAzvaUro69gurw%40mail.gmail.com.
No comments:
Post a Comment