B
B
blackbb2018-08-16 11:03:40
Django
blackbb, 2018-08-16 11:03:40

How to display two languages ​​in a form in Django-modeltranslation?

There is a model:

class Cargo(models.Model):
    """Base model of cargo"""
    company = models.ForeignKey(Profile, on_delete=models.CASCADE, verbose_name=_('Company'))
    title = models.CharField(max_length=500, verbose_name=_('Title'))
    slug = models.SlugField(unique=True, verbose_name=_('URL address'))
    description = tinymce_models.HTMLField(verbose_name=_('Description'))

translation.py
@register(Cargo )
class CargoTranslationOptions(TranslationOptions):
    fields = ('title', 'description',)

forms.py
class CargoAddForm(TranslationModelForm):
    class Meta:
        model = Cargo
        fields = '__all__'

views.py
class CargoAdd(CreateView):
    """Add Cargo in profile"""
    model = Cargo
    form_class = CargoAddForm

I display this form in the template and the usual form without fields in English and Russian is displayed. I understand that when you change the language on the site, you can fill in the fields in this language in the form, but the problem is that the page reloads when you change the language and all the entered data in Russian is lost. How to implement the addition of this model with the output of fields in two languages?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question