Reference: Forms¶
This module contains the form utilities for the Translations app.
- translations.forms.generate_translation_form(translatable)[source]¶
Return the
Translation
form based on aTranslatable
model and the translation languages.Generates the
Translation
form based on the translatable fields of theTranslatable
model and the translation languages and returns it.- Parameters:
translatable (type(Translatable)) – The
Translatable
model to generate theTranslation
form based on.- Returns:
The
Translation
form generated based on theTranslatable
model and the translation languages.- Return type:
- Raises:
ValueError – If the default language code is not supported.
To get the
Translation
form based on aTranslatable
model and the translation languages:from translations.forms import generate_translation_form from sample.models import Continent # get the translation form form = generate_translation_form(Continent) print(form.declared_fields['field'].choices) print(form.declared_fields['language'].choices)
[ (None, '---------'), ('name', 'Name'), ('denonym', 'Denonym'), ] [ (None, '---------'), ('en-gb', 'English (Great Britain)'), ('de', 'German'), ('tr', 'Turkish'), ]