Skip to main content

django-dbfiles

A fork of django-db-storage, updated for modern versions of Django (and renamed for inclusion in PyPI).

Overview

Warning: In many cases, storing files in the database is a BAD idea. Your database will easily become bloated and 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

Admin List Admin Edit

Requirements

  • Python 3.10 or above
  • Django 4.2 or above

Installation

Installation using pip:

pip install django-dbfiles

Update settings.py:

# Add 'dbfiles' to INSTALLED_APPS
INSTALLED_APPS = [
    'dbfiles',
]

# Optionally set DEFAULT_FILE_STORAGE
DEFAULT_FILE_STORAGE = 'dbfiles.storage.DBStorage'

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

Update urls.py:

urlpatterns = [
    ...
    dbfiles_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)

Moving from django-db-storage?

If you are switching to this package from django-db-storage and want to keep your existing db_file table, let Django know about the app name change by running the following SQL:

UPDATE django_migrations SET app = 'dbfiles' WHERE app = 'dbstorage';

Bugs?

Create an issue at https://github.com/imsweb/django-dbfiles/issues

Release files for django-dbfiles 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-dbfiles 3.2.0
File Size Uploaded
django_dbfiles-3.2.0.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-dbfiles 3.2.0
File Interpreter ABI Platform
django_dbfiles-3.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / django_dbfiles-3.2.0.tar.gz

Download URL django_dbfiles-3.2.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
cb7edec9725f84c2891c2d60b04455c3b8db3152b9c9f20598b53f8ae72f4ca6
BLAKE2b-256 checksum
How to use checksums
e85cf859e9330fa64dc3f3b0e242c9067ba2452c805e94a8cda792b7a2416c62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / django_dbfiles-3.2.0-py3-none-any.whl

Download URL django_dbfiles-3.2.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0151f65173a3eb36b04245c87e437b9f561e3a6307edad4ca807c3afe9e127aa
BLAKE2b-256 checksum
How to use checksums
24eeebdca79adcd07320ae022bb99cf80817af6762b0747821e4c47aca884ce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page