1

I have a django project in which the admins are able to upload media. As items sell, they are deleted from the site, thus removing their entry in the MySQL database. The images associated with the item, however, remain on the file system. This isn't neccessarily bad behavior - I don't mind keeping files around in case a deletion was an accident. The problem I forsee is two years from now, when storage space is limited because of a media folder bloated with old product images.

Does anyone know of a systematic/programmatic way to sort through ALL the images and compare them to the relevant MySQL fields, deleting any image which DOESN'T have a match from the filesystem? In the perfect world I'm imagining a button in the django-admin like "Clean-up unused media" which executes a python script capable of this behavior. I'll be sharing whatever my eventual solution is here, but what I'm looking for right now is anyone who has ideas, knows resources, or has done this at some point themselves.

1 Answer 1

0

You can use Django Cleanup, install it with pip install django_cleanup and add django_cleanup to installed_apps in your settings.py and it will do the trick but however it will not delete the old images, so you have to delete them manually. The link to Django Cleanup. Make sure the Python and Django versions are capable of the Django cleanup version you use.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .