Skip to main content

Django storage backend for storing files in your database.

Project description

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.8 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

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_dbfiles-3.0.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

django_dbfiles-3.0.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file django_dbfiles-3.0.0.tar.gz.

File metadata

  • Download URL: django_dbfiles-3.0.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for django_dbfiles-3.0.0.tar.gz
Algorithm Hash digest
SHA256 df5cb13fb7f388896fd336bedc5798f26d84fec4a19f6be59eb82a2a0fd8f4c8
MD5 68fecfa9481ba62297c1f30e92311638
BLAKE2b-256 f418b67bf90d3bc49a38fd9eba63373dd61c8ab45367195d6ef2836f8d9144b4

See more details on using hashes here.

File details

Details for the file django_dbfiles-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dbfiles-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c949e1b1aa784306de3d80d3af802fb1788c36ef6d106de2ad63ad3e46f781c
MD5 3d4d0bc994943d8d0b7352d3f46abf3d
BLAKE2b-256 9f5a44ea0727789902cd7a9fa2247513476306d8098f26265c83ddef7d0bb9d6

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