Thursday, November 15, 2012

Re: managing files, deleting file from file system with admin site

Thanks! Both methods are useful.

четверг, 15 ноября 2012 г., 18:02:02 UTC+4 пользователь lingrlongr написал:
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 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/-/Xy0lEmzFy6kJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate