hvad.forms

TranslatableModelFormMetaclass

class hvad.forms.TranslatableModelFormMetaclass

Metaclass of TranslatableModelForm.

__new__(cls, name, bases, attrs)

The main thing happening in this metaclass is that the declared and base fields on the form are built by calling django.forms.models.fields_for_model() using the correct model depending on whether the field is translated or not. This metaclass also enforces the translations accessor and the master foreign key to be excluded.

TranslatableModelForm

class hvad.forms.TranslatableModelForm(ModelForm)
__metaclass__

TranslatableMOdelFormMetaclass

__init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, label_suffix=':', empty_permitted=False, instance=None)

If this class is initialized with an instance, it updates initial to also contain the data from the Translations Model if it can be found.

save(self, commit=True)

Saves both the Shared Model and Translations Model and returns a combined model. The Translations Model is either altered if it already exists on the Shared Model for the current language (which is fetched from the language_code field on the form or the current active language) or newly created.

Note

Other than in a normal django.forms.ModelForm, this method creates two queries instead of one.

Read the Docs v: latest
Versions
latest
0.0.3
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.