Reputation: 45108
I'm using django-transmeta to help with my multi-lingual models. Here's an example model of mine:
class Edition(models.Model):
__metaclass__ = TransMeta
name = models.CharField(max_length=64)
Could anyone tell me how I can get the value of the name
field in the default language. I'd like to override the __unicode__
method of the model so I can display a meaningful title. Currently it is displayed as Edition Object
and is not very helpful.
Thanks.
Edit: I've managed to do it like this but this relies on the fact the language code is hardcoded.
class Edition(models.Model):
__metaclass__ = TransMeta
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name_en
Upvotes: 2
Views: 252
Reputation: 17105
ModelTranslation uses the same convention (_en, _fr, ...) but makes use of it transparently depending on the current request language.
https://github.com/deschler/django-modeltranslation
Also, it's still currently active.
Upvotes: 1
Reputation: 3974
Hi I am a developer of django-transmeta. For each internationalized field, you have a property with the name field original.
edition = Edition.objects.all()[0]
print edition.name
print edition.name_en
print edition.name == edition.name_en
If it's not work, you should check LANGUAGE_CODE and TRANSMETA_DEFAULT_LANGUAGE (this is optional) in your settings
Upvotes: 2