DEV Community

Charisma Elohe
Charisma Elohe

Posted on

Deleting unused media files in Django (Step by step)


We seldom have projects (web projects for example) that lack media files. A good example is, images. Images give unmatched and accurate description that words would have failed to bring out.

We can load media as static elements on your web application or have them stored in the database for retrieval and rendering. The latter is used for major projects - where we only store what we need and can use.
It is possible to deplete your space (or unnecessarily occupy it) with media files that we upload.

It can be quite hectic to go through the deletion process. On the flip side, there is possibility to automatically clean up the unused media files from our project. We depend on a clean package for this.

Installation
This can be done on your virtual environment (like I have done) or entire system , depending on the user’s preference.

pip install django-cleanup

Image description

In the settings.py file, under the installed_apps, add the following line

‘django_cleanup.apps.CleanupConfig’

Image description

Top comments (0)