Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Custom Database Storage for Django

Project Description


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


  • Python (2.7, 3.4, 3.5)
  • Django (1.8, 1.9)


Installation using pip:

$ pip install django-db-storage


# Add 'dbstorage' to INSTALLED_APPS


# Choose a root url for uploaded files
MEDIA_URL = '/media/'


urlpatterns = [

Run database migrations

$ python migrate

How to Use

No modification are needed for models to work properly.

def user_directory_path(instance, filename):
    return 'user_{0}/{1}'.format(, 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)
Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_db_storage-1.0.2-py2.py3-none-any.whl (7.2 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Feb 28, 2016
django-db-storage-1.0.2.tar.gz (5.8 kB) Copy SHA256 Checksum SHA256 Source Feb 28, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting