No project description provided
Project description
django-blob-storage
This is a fork from django-db-storage2
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.
.. _StackExchange post: http://programmers.stackexchange.com/questions/150669/is-it-a-bad-practice-to-store-large-files-10-mb-in-a-database
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
- only db files need to be backed up
Requirements
- Python (3.5+)
- Django (3.2+)
Installation
Installation using pip::
$ pip install django-blob-storage
Update settings.py
# Add 'dbstorage' to INSTALLED_APPS
INSTALLED_APPS = [
'dbstorage',
]
# Optionally set DEFAULT_FILE_STORAGE
DEFAULT_FILE_STORAGE = 'dbstorage.storage.DBStorage'
# Optionally for tracking file accesses (currently over view)
# DJANGO_DBFILE_TRACK_ACCESSED=True
# Optionally set another db than default
# DJANGO_DBFILE_DB = "foo"
# Choose a root url for uploaded files
MEDIA_URL = '/media/'
Update urls.py
urlpatterns = [
...
# dbstorage
path("", include("dbstorage.urls")),
]
Run database migrations (done automatically, when included as app)
env DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH="." poetry run django-admin 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/devkral/django-blob-storage/issues
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
Built Distribution
Hashes for django_blob_storage-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45018e1f2117d900b97f854550c0799635a80b8397377dd207902304a2312af6 |
|
MD5 | 1ed2d785ed68352157657582491e8851 |
|
BLAKE2b-256 | af0e6419c5ca4ca716ba79d9416bd2364a9803df27f294b95d8ec84dc2cb5d88 |
Hashes for django_blob_storage-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f442adef8b451b444115f2419b0a9bc37458982e67590be83652de60711c8ae |
|
MD5 | 5f5f24fdeb9b9c2f6e4d819632d1a487 |
|
BLAKE2b-256 | 474bf07e29107b9a1d0e011534f515831f0f8614befbf31d2486a4c0f570d6f6 |