deschler/django-modeltranslation — pull request #145 by wrwrwr (2013-02-18 20:15:24+00:00)
Title: Population with get_or_create and fixtures, more modes and switching methods

Some extensions to the auto population that I'd like to get some opinions on, maybe some of it would be useful in the general case.

First is support for auto population when loading fixtures or using ``get_or_create``. Consider having to work with some untranslated third-party fixtures and having something other than `en-us` as the default language (which Django forces when executing any command, including ``loaddata``). The solution is to use the ``pre_save`` signal to fill missing translations no matter how the model is created.

This unfortunately breaks semantics for the ``title='foo', title_def_lang='bar'`` case (note the commented out test case). You don't see ``foo`` at all with such implementation, so the value for the default language wins. it can be amended for ``create`` and possibly for ``get_or_create``, but I'd rather have the same semantics for all cases -- maybe someone can come with something that would make it work for fixtures (in some non-horribly-hackish way ;-)

Secondly, I'd like to propose adding some weaker population modes:
-- ``default`` populates only the default translation (so at most two translations are set -- the current and the default); useful if you only need to ensure a fallback value is available, but wouldn't like to assume the same value for all languages;
-- ``required`` is even weaker, only sets the default translation if the original field was non-nullable; useful if you'd really rather not populate anything, but need to preserve integrity of the database (if some code relies on not having null for the original field, with modeltranslation with fallbacks it's likely to rely on not having null for the default translation).

Thirdly, there are two new ways of switching population mode:
-- manager toggle, e.g.: ``objects.populate(mode)``;
-- context manager, e.g.: ``with auto_populate(mode)``,
not very significant, but I find them useful in some places.