Custom Database Storage for Django
Project description
Overview
Warning: In many cases, storing files in the database is a BAD idea. Your database will easily become bloated and the performance can degrade rapidly. See this StackExchange post for more information.
This is a custom storage backend for storing files in the database instead of the file system and is a drop-in replacement for Django’s FileSystemStorage. Some benefits of this application:
no changes needed to existing models, it just works (and if it doesn’t, open a ticket!)
django-admin is implemented and can be used to search, upload, download and manage files
100% code coverage with unit tests
Requirements
Python (2.7, 3.4, 3.5)
Django (1.8, 1.9)
Installation
Installation using pip:
$ pip install django-db-storage
Update settings.py
# Add 'dbstorage' to INSTALLED_APPS
INSTALLED_APPS = [
'dbstorage',
]
# Optionally set DEFAULT_FILE_STORAGE
DEFAULT_FILE_STORAGE = 'dbstorage.storage.DBStorage'
# Choose a root url for uploaded files
MEDIA_URL = '/media/'
Update urls.py
urlpatterns = [
...
dbstorage_url(),
]
Run database migrations
$ python manage.py migrate
How to Use
No modification are needed for models to work properly.
def user_directory_path(instance, filename):
return 'user_{0}/{1}'.format(instance.user.id, filename)
class MyModel(models.Model):
file_field1 = models.FileField()
file_field2 = models.FileField(upload_to='uploads/%Y/%m/%d/')
file_field3 = models.FileField(upload_to=user_directory_path)
Bugs?
Create an issue at https://github.com/derekkwok/django-db-storage/issues
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
Built Distribution
Hashes for django_db_storage-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d621cf874d8edebabab7e390c78b9543b8d842b10bc978aa1665a64523af0f6a |
|
MD5 | ec476f5f58bee05c8c6a7b0c238097ae |
|
BLAKE2b-256 | 94b6d825aa2ca6414597e61b007521927ab5cbf403d6fab52f79583a9f9d0795 |