1 2 3 4 5 6 7 8 9 10 11 | from django.conf import settings
class LanguageField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs.setdefault('maxlength', 5)
kwargs.setdefault('choices', settings.LANGUAGES)
super(LanguageField, self).__init__(*args, **kwargs)
def get_internal_type(self):
return "CharField"
|
More like this
- CountryField by marinho 5 years, 5 months ago
- CustomChoiceField, Selectable label field version of ModelChoiceField by mauro 5 years, 2 months ago
- Little middleware that create a facebook user by marinho 5 years, 5 months ago
- User post_save signal to auto create 'admin' profile by marinho 5 years, 5 months ago
- Class ModelInfo for show object info by marinho 4 years, 10 months ago
Comments
Thanks for the snippet.
A little typo: in Line 5 it must be 'max_length' instead of 'maxlength'
#
Although this snippet is rather old, it still works fine... :) If you want to use I18N, you should use this:
Also, 5 chars is not enough anymore, for example sr-latn has 7.
#