I've use something like this: class Car(models.Model): #some fields photo = models.ImageField(upload_to='cars')
def delete(self, *args, **kwargs): storage, path = self.photo.storage, self.photo.path super(Car, self).delete(*args, **kwargs) storage.delete(path) On Thursday, November 15, 2012 12:48:16 AM UTC-5, Sergey Seleznev wrote: > > Hi! I'm new to python and django(well, and web dev too). > I'm using python 2.7 and django 1.4 > I went through the tutorial and then got issue with files managing. > I have model like this: > > class Car(models.Model): > #some fields > photo = models.ImageField(upload_to='cars') > > and media url/root configured in settings.py. > Also I have autogenerated django admin site. > Its works well and I can upload files to MEDIA_ROOT/cars/ automaticaly > when adding new object to Car model, but when I delete or change that > object from admin site old file doesnt deletes. > I need some easy and a good way to configure > model/admin_site/something_else to delete old files from file system when i > change/delete model object from admin site. > I think admin > actions<https://docs.djangoproject.com/en/1.4/ref/contrib/admin/actions/> can > be solution, but dont think it helps in case of changes and it cant help > override "Delete" button from object edit page. > > Thanks for your help! > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/rWzjWwB7VhkJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.