Skip to main content

Custom Database Storage for Django

Project description

django-db-storage2

.. image:: https://travis-ci.org/derekkwok/django-db-storage.svg?branch=master :target: https://travis-ci.org/derekkwok/django-db-storage

.. image:: https://coveralls.io/repos/github/derekkwok/django-db-storage/badge.svg?branch=master :target: https://coveralls.io/github/derekkwok/django-db-storage?branch=master

.. image:: https://badge.fury.io/py/django-db-storage.svg :target: https://badge.fury.io/py/django-db-storage

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

.. image:: http://i.imgur.com/4g9tmEZt.png :target: http://i.imgur.com/4g9tmEZ.png

.. image:: http://i.imgur.com/A2F8xlrt.png :target: http://i.imgur.com/A2F8xlr.png

Requirements

  • Python (3.5+)
  • Django (1.11.17+)

Installation

Installation using pip::

$ pip install django-db-storage2

Update settings.py

.. code-block:: python

# 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

.. code-block:: python

urlpatterns = [
    ...
    dbstorage_url(),
]

Run database migrations

::

$ python manage.py migrate

How to Use

No modification are needed for models to work properly.

.. code-block:: python

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-db-storage2-2.0.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

django_db_storage2-2.0.1-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-db-storage2-2.0.1.tar.gz.

File metadata

  • Download URL: django-db-storage2-2.0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for django-db-storage2-2.0.1.tar.gz
Algorithm Hash digest
SHA256 97409e0d71a5e73c4ae82a0ec92c81bffa0c41c61cfd2911524be844a52deca0
MD5 6cc1f0ca0ac7bd13706943e3bfa96f59
BLAKE2b-256 b5ebd8babad5c7936aa184fbaf9c2cb224596ccaf0e28962015367d35ca33082

See more details on using hashes here.

File details

Details for the file django_db_storage2-2.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_db_storage2-2.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for django_db_storage2-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b2a903e05ca3d7b53d93539220569420a31f6cf60bc58417b30b5846f7523fe
MD5 dba3414277836b7cae4be036dbed7f57
BLAKE2b-256 64156961292eb673eca678cbb33d23da6c385c1541e07a3257daf920c656e334

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page