i have a Model for a user profile in my django app that has a models.ImageField and i have an ModelAdmin for it when a user uploads an image , in the admin page , when i go in that user's Customize page , in the ImageField section , there is the url of uploaded image and a checkbox named "Clear" and a button for updating the image. how can i change the text of that checkbox ? for example i want it to have the text "Delete" instead of "Clear"
Asked
Active
Viewed 3,048 times
1
1 Answers
3
It seems like "Clear" is hardcode.
So either you create a custom widget simply like that:
class MyClearableFileInput(ClearableFileInput):
clear_checkbox_label = ugettext_lazy('Delete')
And assign it to your form field like that
MyForm(forms.Form):
myfile=ImageField(widget=MyClearableFileInput)
Or add overwrite it in your admin
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.ImageField: {'widget': MyClearableFileInput},
}
Or you use the translation mechanisms to translate Clear into Delete. Django translation is described in the docs pretty well.
I personally, just think that it is quite some overhead for your problem, unless you are using translations anyway. I would clearly recommend the custom widget - the addtional code is really minimal.

schacki
- 9,401
- 5
- 29
- 32
-
i just want to edit these : class MyModel(models.Model) class MyModelAdmin(admin.ModelAdmin) not add or edit anything else like "class MyClearableFileInput(ClearableFileInput)" What should i do ? – Kozet Aug 22 '12 at 10:22
-
as I wrote, your second option is translation. Although it would help, if you explained in more detail, why you can't go for the other approach. As I said, "Clear" is hardcoded. No easy way around it! – schacki Aug 22 '12 at 11:05
-
how can i change the translation of 'clear' in django translation mechanism ? – Kozet Aug 28 '12 at 06:38
-
I just updated my answer. If you are still hesitant to create your custom widget, please share some more details of your concerns. – schacki Aug 28 '12 at 06:45
-
how can i assign class MyClearableFileInput(ClearableFileInput) in to my form field ? – Kozet Aug 28 '12 at 06:56
-
it's a models.ImageField and it has no argument 'widget' – Kozet Aug 28 '12 at 07:14