The widget for FileField and ImageField has a problem: it doesn't supports clear its value and it doesn't delete the old file when you replace it for a new one.
This is a solution for this. It is just for Admin, but you can make changes to be compatible with common forms.
The jQuery code will put an <input type="checkbox"> tag next to every <input type="file"> and user can check it to clear the field value.
When a user just replace the current file for a new one, the old file will be deleted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
More like this
- Stuff by NixonDash 1 month ago
- Add custom fields to the built-in Group model by jmoppel 3 months, 1 week ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 3 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 7 months, 1 week ago
- Browser-native date input field by kytta 8 months, 3 weeks ago
How would I change this to work with regular forms?
This snippet works great for me.I was using Django1.2.5 and its a kind of facility provided in Django1.4b. I wanted this to work in admin and it worked perfectly.
Thanks marinho . Great
Please login first before commenting.