Reference: Forms¶
This module contains the form utilities for the Translations app.
- translations.forms.generate_translation_form(translatable)[source]¶
Return the
Translationform based on aTranslatablemodel and the translation languages.Generates the
Translationform based on the translatable fields of theTranslatablemodel and the translation languages and returns it.- Parameters:
translatable (type(Translatable)) – The
Translatablemodel to generate theTranslationform based on.- Returns:
The
Translationform generated based on theTranslatablemodel and the translation languages.- Return type:
- Raises:
ValueError – If the default language code is not supported.
To get the
Translationform based on aTranslatablemodel 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'), ]