You can reuse the make_choices function for other choices fields.
Bad side: bin/make_messages.py won't get the choices values automatically, you have to add them in the .po's by hand.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
fromdjango.dbimportmodelsfromdjango.utils.translationimportugettext_lazyas_defmake_choices(choices):""" Returns tuples of localized choices based on the dict choices parameter. Uses lazy translation for choices names. """returntuple([(k,_(v))fork,vinchoices.items()])classQuality(models.Model):QUALITY_CHOICES={1:'bad',2:'regular',3:'good',}q=models.PositiveSmallIntegerField(choices=make_choices(QUALITY_CHOICES))classAdmin:pass
Comments
Please login first before commenting.