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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-db-storage-1.0.2.tar.gz.
File metadata
- Download URL: django-db-storage-1.0.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f49af3fb11e34f8c52de170e6b8ed1b4203fe2ab9e2996789371617df9ed98e5
|
|
| MD5 |
97fd409ed25c024b7d1538dd21062113
|
|
| BLAKE2b-256 |
fbb2ec06608f1e086dbc06cfb46c722bbc7430a4a8fd966a784d514165bff8a7
|
File details
Details for the file django_db_storage-1.0.2-py2.py3-none-any.whl.
File metadata
- Download URL: django_db_storage-1.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21cf8f1e98e6c0bbd3016c4d8a41dcfd1a02ba6de828b6735469a1a593bf83a2
|
|
| MD5 |
4208a5134841ea4195695de054060a13
|
|
| BLAKE2b-256 |
0438c8fc4dcd6ea2c9fad7ea379fc7b583e83629e744bd6e1ee9eb2c31bc1589
|