from django.utils.translation import ugettext_lazy as _
class Person (models.Model):
GENDER = (
(0, _('Male'),
(1,_('Female')
)
name = models.CharField(maxlength=100)
gender = models.IntegerField(choices=GENDER)
and i show it on the form with localized output ....
after submit i get values ( 0,"name" ) in the database.
Question is how to show query from database on template with localized
output
TIA,
Damir
Try this in your template (assuming p is a person model instance
available to your template):
{{ p.get_gender_display }}
See: http://www.djangoproject.com/documentation/db-api/#get-foo-display
Also, another suggestion: consider using more intuitive keys for your
gender field instead of 0, 1. You could define it as a CharField and
change choices keys to M, F instead of 0, 1 (or even better "male",
"female"). If you're worried about performance, you can even set
db_index=True on the gender field.
Damir