D
D
devalone2017-03-08 01:45:21
Django
devalone, 2017-03-08 01:45:21

How to russify all fields in the django admin?

There is the following model:

class Work(models.Model):                                                        
    photo = models.ImageField(upload_to='works_work_photos',                     
                              verbose_name='фото')                               
    description = models.CharField(max_length=1500, null=True, blank=True,       
                                   verbose_name='описание')                      
                                                                                 
    def __str__(self):                                                           
        return "Проект " + str(self.pk) + ": " + self.description[:100]          
                                                                                 
    class Meta:                                                                  
        verbose_name = 'проект'                                                  
        verbose_name_plural = 'проекты'

And here are the admin settings:
class WorkModelForm(forms.ModelForm):
    description = forms.CharField(widget=forms.Textarea, required=False)

    class Meta:
        model = Work
        fields = "__all__"


class WorkAdmin(admin.ModelAdmin):
    form = WorkModelForm

admin.site.register(Work, WorkAdmin)

But the description field is not translated, for some reason.
PS yes, I know that it is correct to use django.utils.translation and generate translation via manage.py makemessages, but I will only have one language

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-03-08
@devalone

Of course "not translated", but for some reason you redefined the field in the form. If you really need it, then you should give it a label parameter:

class WorkModelForm(forms.ModelForm):
    description = forms.CharField(label='описание', widget=forms.Textarea, required=False)
    ...

But I suspect you didn't, that you just needed to set the widget for this field :
class WorkModelForm(forms.ModelForm):
    class Meta:
        model = Work
        fields = "__all__"
        widgets = {
            'description': forms.Textarea,
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question