django-orphaned

delete all orphaned files created by django (FileField)

4 years after

about

delete all orphaned files

setup

install via easy_install or pip

easy_install django-orphaned

with pip

pip install django-orphaned

add it to installed apps in django settings.py

INSTALLED_APPS = (
    'django_orphaned',
    ...
)

now add this to your settings.py ('app' is your project name where models.py is located):

ORPHANED_APPS_MEDIABASE_DIRS = {
    'app': {
        'root': MEDIABASE_ROOT,  # MEDIABASE_ROOT => default location(s) of your uploaded items e.g. /var/www/mediabase
        'skip': (               # optional iterable of subfolders to preserve, e.g. sorl.thumbnail cache
            path.join(MEDIABASE_ROOT, 'cache'),
            path.join(MEDIABASE_ROOT, 'foobar'),
        ),
        'exclude': ('.gitignore',) # optional iterable of files to preserve
    }
}

if you have multiple apps with the same media root like:

ORPHANED_APPS_MEDIABASE_DIRS = {
    'app1': {
        'root': MEDIA_ROOT,
    },
    'app2': {
        'root': MEDIA_ROOT,
    },
}

django-orphaned will not delete files needed only in one of them.

NOTE: from version 0.4.2 you can define ''root'' as string or iterable (list, array)

the least to do is to run this command to show all orphaned files

python manage.py deleteorphaned --info

and to finally delete all orphaned files

python manage.py deleteorphaned

license

MIT-License, see LICENSE file.

Related Repositories

munki-do

munki-do

...

django-imaging

django-imaging

Ajax driven gallery field for django (mostly admin) ...

django-limit-users

django-limit-users

Installable Django app to limit number of enabled user registrations ...

django-maid

django-maid

Django maid cleans up your orphaned media files. ...

django-workflow

django-workflow

A lightweight workflow engine application for Django based web-applications ...


Top Contributors

ledil slamora Tilley zlorf joerick sulami sspross artscoop