Created
October 7, 2010 12:33
-
-
Save ojii/615028 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from django.db import models | |
| from translateable.models import TranslatedModel | |
| class MyModel(TranslatedModel): | |
| non_translated_field = models.IntegerField() | |
| class Translations(models.Model): | |
| translateable_field = models.IntegerField() | |
| class TranslationsMeta: | |
| related_name = 'translations' | |
| fallback_method_name = 'get_fallbacks' | |
| """ | |
| instance.translateable_field | |
| => current translation OR NONE! | |
| instance.translations | |
| => reverse FK from MyModel.Translations | |
| instance.get_fallbacks('de', 'fr', 'ja') | |
| => populates translatable properties on 'instance' which are NOT filled | |
| with the values from the languages requested, in that order. | |
| EG: we have fields 'one', 'two', 'three' and 'four'. | |
| current language is 'de'. | |
| German translation: | |
| one: 'eins' | |
| two: None | |
| three: None | |
| four: None | |
| English Translation: | |
| one: 'one' | |
| two: 'two' | |
| three: None | |
| four: None | |
| Japanese Translation: | |
| one: '一', | |
| two: '二', | |
| three: '三', | |
| four: '四', | |
| instance = Model.objects.get(pk=something) | |
| instance.one => 'eins' | |
| instance.two => None | |
| instance.three => None | |
| instance.four => None | |
| instance.get_fallbacks('en', 'ja') | |
| instance.one => 'eins' | |
| instance.two => 'two' | |
| instance.three => '三' | |
| instance.four => '四' | |
| MyModel.objects.all().with_fallbacks('de', 'ja') | |
| => FROZENQuerySet which does 2 queries: one for the objects, one for | |
| fallbacks, does the 'fallback-setting' in python in iterator | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment