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.6, 3.7 are tested with tox.

    Django 1.8, 1.9, 1.10, 1.11, 2.0, 2.1 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

By 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

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

Verbosity level. 0 - minimal output, 1 - normal output (default)

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.13.tar.gz (8.6 kB view details)

Uploaded Source

Built Distributions

django_unused_media-0.1.13-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

django_unused_media-0.1.13-py2-none-any.whl (11.7 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: django-unused-media-0.1.13.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for django-unused-media-0.1.13.tar.gz
Algorithm Hash digest
SHA256 85d41d00a678cb91fc2f38a4396ac4069a05079b74493e44d1aea09d5cc83d93
MD5 df188b2a1cf0887d2ce906e1dfbc9ea5
BLAKE2b-256 e435e1eb0c49626d422eca08388caedaf80480ab82545bfc46df4b972d5304cd

See more details on using hashes here.

File details

Details for the file django_unused_media-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: django_unused_media-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for django_unused_media-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 6971fd37e46aa58ab0b5f461581c86dd8a6547f57d45ffa5f72cc94bf36116f4
MD5 44ed40a1133fe266ad686f55a798f9bb
BLAKE2b-256 e306f4962a8eee27c735b4e6a2bc831df04762a286f2c0621b0e29789acc50c3

See more details on using hashes here.

File details

Details for the file django_unused_media-0.1.13-py2-none-any.whl.

File metadata

  • Download URL: django_unused_media-0.1.13-py2-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.10

File hashes

Hashes for django_unused_media-0.1.13-py2-none-any.whl
Algorithm Hash digest
SHA256 90dd74bc3ca07310b3a10e52ccbb3bd3693a77d3c864131d53df12162951b942
MD5 1f41f0cc8fb64eb1f08edece51aa42f0
BLAKE2b-256 48e89a11c6b669cdc1ed0168cfa55698b734e55d852da67deebbea32defeb13f

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