Skip to main content

Delete unused media files from Django project

build-status-image PyPI

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

  1. Install django-unused-media: pip install django-unused-media

    Python 2.7, 3.6, 3.7, pypy are tested with tox.

    Django 1.8, 1.9, 1.10, 1.11, 2.0, 2.1, 2.2, 3.0 are tested with tox.

  2. Add django-unused-media to INSTALLED_APPS: python INSTALLED_APPS = ( ... 'django_unused_media', ... )

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. - ``*`` as any symbol is supported. - Can use multiple options in one command.

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)

Tests

At first make sure that you are in virtualenv if you use it.

Install all dependencies:

make setup

To run tests:

make test

To run static analyser:

make flake8

License

MIT licence

Release files for django-unused-media 0.2.2

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 0.2.2
File Size Uploaded
django-unused-media-0.2.2.tar.gz 6.3 kB Details

Built distribution (wheel)

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

Total release size: 18.4 kB

Release files / django-unused-media-0.2.2.tar.gz

Download URL django-unused-media-0.2.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8f46b5a7d3e10f09e31126aefb2efe24e3dedb6a89daf786f7e055c5298668ee
BLAKE2b-256 checksum
How to use checksums
285b58598b4397cf1d5480206c34a0baa201e782627c079cb208369a3a855f00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

Release files / django_unused_media-0.2.2-py3-none-any.whl

Download URL django_unused_media-0.2.2-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
390d0cfa4ac9e4d0c4de0878b42bda41ed188fa62b0032fdf0a266e7136ce013
BLAKE2b-256 checksum
How to use checksums
4948b8ca3f24a7df20718456c3d7630f4bbfa1017f19d64d50d9d1d3282e697a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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