Skip to main content

Delete unused media files from Django project

Package provides management command cleanup_unused_media for Django applications.

You can remove all not used media files (files without references from any Django model with FileField or ImageField fields or their inheritances).

Installation

pip install django-unused-media-cleaner
Add *unused_media_cleaner* to INSTALLED_APPS.

Usage

To cleanup all unused media files, run management command:

./manage.py cleanup_unused_media

By default command is running in interactive mode. List of files which are going to be removed will be displayed for confirmation. User has to confirm the action.

Options

--noinput, --no-input

Non interactive mode. Command will remove files without any confirmation from the user. Useful for scripts.

./manage.py cleanup_unused_media --noinput

-e, --exclude

To avoid operating on particular files you can use exclude option.

  • --exclude=PATTERN or -e=PATTERN
  • The pattern is specified similarly to the pattern for the --exclude argument in the rsync utility.
  • * as any symbol is supported.
  • Can use multiple options in one command.
  • Can be used to exclude certain directories from processing. Example: --exclude='somedir/'

For example, to keep .gitignore and *.png files you can use:

./manage.py cleanup_unused_media -e *.gitignore -e *.png

Also you can exclude entire folder or some files in that folder (path should be relative to settings.MEDIA_ROOT):

./manage.py cleanup_unused_media -e path/to/dir/* -e path/to/dir/my*.doc

--minimum-file-age, seconds

Default = 60 (one minute)

Minimum file age to consider for cleanup. All files younger this age will be skipped.

--remove-empty-dirs

By default script keeps empty dirs in media folder. But with this option all empty directories will be removed after cleaning process automatically.

--dry-run

Dry run without any affect on your data

--verbosity {0,1,2}, -v {0,1,2}

Verbosity level.

  • 0 - silent
  • 1 - normal output (default)
  • 2 - verbose output (list individual files)

Testing (for developers)

uv sync --extra test
uv run pytest

Cheks

uv run ruff check .
uv run ruff check --fix .
uv run ruff format .
uv run ruff format --check .

License

MIT

Metadata

Release files for django-unused-media-cleaner 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-unused-media-cleaner 0.1.0
File Size Uploaded Provenance
django_unused_media_cleaner-0.1.0.tar.gz 9.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-unused-media-cleaner 0.1.0
File Interpreter ABI Platform
django_unused_media_cleaner-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / django_unused_media_cleaner-0.1.0.tar.gz

Download URL django_unused_media_cleaner-0.1.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7c5445704f4a115501e4b19a34cdf58aee1616426ffaf3e004f6c98b6f856a24
BLAKE2b-256 checksum
How to use checksums
ca37fc178fbabf67bebea5520be268bbfb7b0f4f26777295fdae7b8f964a10be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":null,"id":"forky","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / django_unused_media_cleaner-0.1.0-py3-none-any.whl

Download URL django_unused_media_cleaner-0.1.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32409bd93b2ae9bd1a0f32083920e09b9dc7b5d940368a518d55ee2d3c947105
BLAKE2b-256 checksum
How to use checksums
7419409c008707b92272529a75418d98c0aeb1384ede427c2941007941f20c65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":null,"id":"forky","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for django-unused-media-cleaner 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page