Translated choices fields

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
from django.db import models
from django.utils.translation import ugettext_lazy as _

def make_choices(choices):
    """
    Returns tuples of localized choices based on the dict choices parameter.
    Uses lazy translation for choices names.
    """
    return tuple([(k, _(v)) for k, v in choices.items()])

class Quality(models.Model):
    QUALITY_CHOICES = {
        1: 'bad',
        2: 'regular',
        3: 'good',
    }
    q = models.PositiveSmallIntegerField(choices=make_choices(QUALITY_CHOICES))
    class Admin: pass

More like this

  1. i18n base model for translatable content by foxbunny 4 years, 11 months ago
  2. Admin Apps Names Translation by Nad/ 3 years, 4 months ago
  3. Modeli18n by pavl 3 years ago
  4. Extended i18n base model by alcinnz 2 months, 1 week ago
  5. autotranslate po files using google translate by dnordberg 4 years, 9 months ago

Comments

(Forgotten your password?)