The super storage backend
Project description
If making sure your file uploads are never duplicated is more important than organising your files into neat folders, you might want to try this package.
Usage
You can use the storage backend on a global level by adding the following to your django settings:
DEFAULT_FILE_STORAGE = 'dedupebackend.storage.DedupedStorage'
If you want to use the other features offered by dedupebackend, you need to add dedupebackend to INSTALLED_APPS like this:
INSTALLED_APPS = [ 'dedupebackend', # does not matter what spot ... ]
Admin integration
Adding dedupebackend to INSTALLED_APPS gives you an admin page where you can check your uploaded files. I allready let you know dedupebackend just throws verything in a large folder, but that does not mean you can not add structure to the storage. Just not on a filesystem level. You should add structure by adding relations to other models. It is easy enough to add categories or something:
class FileCategory(models.Model): files = models.ManyToManyField('dedupebackend.UniqueFile') name = models.TextField()
If you want to add a filter to the dedupebackend admin, try something like this:
from dedupebackend.admin import UniqueFileAdmin from dedupebackend.models import UniqueFile admin.site.unregister(UniqueFile) class CategoryUniqueFileAdmin(UniqueFileAdmin): list_filter = UniqueFileAdmin.list_filter + ('filecategory__name',) admin.site.register(UniqueFile, CategoryUniqueFileAdmin)
that might need some work, I never tested it :p
fields
There are some fields in dedupebackend you can use instead of the django FileField and ImageField. You get a picker added to that, you can use to select a file from the existing uploaded files.
Use something like this:
from dedupebackend.fields import * class KoeHenkModel(model.Model): name = models.TextField() file = UniqueFileField("A normal file, nothing special") image = UniqueImageField("an image")
How does it work?
Well, for each uploaded file, dedupebackend creates a file on disk named after the hash of the file. Mostly the same as git does (I actually tried to use libgit2 for this, but git is bad with deletions). Next to that file, a table holds a record with some information about the file. The primary key of this table is the hash value of the file. So it is really impossible to add duplicates (but but, hash collisions).
The fields actually render a file form field on a foreign key model field. The storage backend returns the hash value as the file name. And it can return file objects when given such a hash value.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-dedupe-backend-0.0.2.tar.gz
.
File metadata
- Download URL: django-dedupe-backend-0.0.2.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ace4a0836a5c3433656b9c2f43e30b232f9e9fc8e6a8fba0005dc04f4fce444 |
|
MD5 | 79a7b262df4d57e76f378ee720c095d2 |
|
BLAKE2b-256 | 983de63b310aed473b0ececebe826699755b4fa008b87cc0406bc3fe3041f133 |