Skip to main content

Delete unused media files from Django project

Project description

Delete unused media files from Django project

build-status-image PyPI

This package provides management command cleanup_unused_media for Django applications. With help of this management command you can remove all media files which are no longer used (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.5, 3.6, PyPy are tested with tox.

    Django 1.6, 1.7, 1.8, 1.9, 1.10, 1.11 are tested with tox.

  2. Add django-unused-media to INSTALLED_APPS:

    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 have to confirm the action.

Options

--noinput, --no-input

Non interactive mode. Command will remove files without any confirmation from 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

--remove-empty-dirs

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

--dry-run

Dry run without any affect on your data

Tests

At first make sure that you are in virtualenv.

Install all dependencies:

make setup

To run tests:

make test

To run static analyser:

make flake8

License

MIT licence

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-unused-media-0.1.12.tar.gz (8.5 kB view details)

Uploaded Source

File details

Details for the file django-unused-media-0.1.12.tar.gz.

File metadata

File hashes

Hashes for django-unused-media-0.1.12.tar.gz
Algorithm Hash digest
SHA256 b1f2a37eefbe72a0c8f7449c902a2963bb40048c5c171bea52d9ac2c0bb424ff
MD5 d966edefa8f169b8f05997942428b34d
BLAKE2b-256 eb46533ff3fe074256655e26e51abaaf1adb25cd8591656887e9f2fac7bb7541

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page