Adds tools for pruning media files from your django project
Project description
Django Prune Media
A Django app that provides management commands for pruning unused media files.
Installation
uv add django-prune-media
Add it to your settings.py.
INSTALLED_APPS = [..., "prune_media", ...]
Usage:
To list or delete the media to be pruned:
python manage.py prune_media --help
Usage: django-admin prune_media [OPTIONS]
Remove unreferenced media files to save space.
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --no-interaction --no-no-interaction Don't ask for confirmation before deleting. [default: no-no-interaction] │
│ --dry-run --no-dry-run Do a dry-run without deleting anything. [default: no-dry-run] │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Django ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version Show program's version number and exit. │
│ --settings TEXT The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the │
│ DJANGO_SETTINGS_MODULE environment variable will be used. │
│ --pythonpath PATH A directory to add to the Python path, e.g. "/home/djangoprojects/myproject". [default: None] │
│ --traceback Raise on CommandError exceptions │
│ --no-color Don't colorize the command output. │
│ --force-color Force colorization of the command output. │
│ --skip-checks Skip system checks. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Or to find empty directories:
python manage.py show_empty_media_dirs
Usage: django-admin show_empty_media_dirs [OPTIONS]
List empty media directories.
The storage API does not support deletion of directories but at least this way you know what can be removed.
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --clean --no-clean Print paths only so they can be piped to other commands [default: no-clean] │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Django ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version Show program's version number and exit. │
│ --settings TEXT The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the │
│ DJANGO_SETTINGS_MODULE environment variable will be used. │
│ --pythonpath PATH A directory to add to the Python path, e.g. "/home/djangoprojects/myproject". [default: None] │
│ --traceback Raise on CommandError exceptions │
│ --no-color Don't colorize the command output. │
│ --force-color Force colorization of the command output. │
│ --skip-checks Skip system checks. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
FAQ
Why another app for this?
Most of the apps I've found operate from the assumption that you are using Django's FileSystemStorage
which is often not the case in production. If you're hosting your media files via a CDN, os.walk
is not going to work for you.
This application solely uses the Django Storage API, which means it works for custom backends like Django Storages too.
What are the limitations?
Django's Storage API doesn't support deleting anything other than files, so you can end up with empty directories. This is why the show_empty_media_dirs
command exists. When using the --clean
option you can pipe the results to a command that's appropriate to your setup.
Should I use this?
🤷♂️
I made this because I didn't want to keep copying this between projects. I want to make it as useful as possible though so contributions, even if it's only a failing test case for me to fix, are very welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_prune_media-0.1.1.tar.gz
.
File metadata
- Download URL: django_prune_media-0.1.1.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.29
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dea335554b5d2ad90fe403736a872daa8c9839535bdd8e4bc51de81c0857b961 |
|
MD5 | 52396ceca47746aa5d6bf631c933cbcf |
|
BLAKE2b-256 | 747c9388d8bf63ea75f782a5ef08c3e15faf6e771ca72c26a772941f0e07d7ef |
File details
Details for the file django_prune_media-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_prune_media-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.4.29
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 990c87a133c745056662eb9cd53a570ee3d56a644d752552dc0df9136fc51309 |
|
MD5 | 998691f5396ab7fc1fc1f50efc22c308 |
|
BLAKE2b-256 | ae3c4616cf66e7f17ee24bacd72f2498fb25a2c2e9b0c1b403150e1a5cfc1a76 |