ojii/django-nani — Issue #43: TranslationAwareManager - access translated fields via ._meta
Author: benzkji
Created: 2011-10-21 14:36:47+00:00
State: open

This problem relates to my need to add a django cms placeholderfield as a translated field. When rendered in the backend, the placeholderfield uses model._meta.get_field_by_name('placeholderfieldname'). This raises an exception, telling me to use a translationAwareManager. But it doesn't work either with a translation aware manager, see django shell output below.

I found a solution, but I'm not sure about implications (one is for sure, it breaks the test suite...). It seems not to be the "how it should be really done" solution, but doesn't seem that wrong either...??
My solution is here: https://github.com/benzkji/django-nani/commit/194ba83ff0d5dcf3c1ba9261f0465716435b224e

----- shell output (date=shared field, description=translated field, placeholderfield) -----
```>>> from app.models.news import News
>>> from nani.utils import get_translation_aware_manager
>>> m = get_translation_aware_manager(News)
>>> qs = m.get_query_set()
>>> qs[0]._meta.get_field_by_name('date')
(, None, True, False)
>>> qs[0]._meta.get_field_by_name('description')
Traceback (most recent call last):
File "", line 1, in
File "/var/www/domains/benzkji/domain.ch/project/nani/utils.py", line 55, in __call__
name)
WrongManager: To access translated fields like 'description' from an untranslated model, you must use a translation aware manager, you can get one using nani.utils.get_translation_aware_manager.
```