KristianOellegaard/django-hvad — pull request #157 by spectras (2014-01-27 03:31:42+00:00)
Title: Translation formset

This is in the same spirit as #131.

In my project, I needed to create a formset of all the translations of a model, so they can be displayed and edited in one go (using a js-based tab view for instance). It turned out being pretty easy to get the basics working (a single regular ModelForm which would not understand translations at all and a formset of _MyModel.\_meta.translations\_model_.

My use case goes a bit beyond. Namely, the translatable model has some validate_unique and custom save() going on that act on both translated and untranslated field (like, concatenate _date_ and _title_ then slugify into a _slug_ field).

I built a translationformset_factory that uses __combine()__ to trigger checks on the translatable model. As a convenience, it also adds language_code to the supplied form if missing, allowing one to write:
```python
class PostTranslationForm(ModelForm):
class Meta:
fields = ['title', 'excerpt', 'content', 'slug']
PostTranslationFormSet = translationformset_factory(
Post, form=PostTranslationForm, extra=1
)
```

It still needs some testing, but I wanted to share the idea and get back some advice to make it better.