Skip to main content

Django Database Files 3000

Build Status

This is a storage system for Django that stores uploaded files in the database. Files can be served from the database (usually a bad idea), the file system, or a CDN.

Installation

Simply install via pip with:

pip install django-database-files-3000

Usage

In settings.py, add database_files to your INSTALLED_APPS and add this line:

DEFAULT_FILE_STORAGE = 'database_files.storage.DatabaseStorage'

Note, the upload_to parameter is still used to synchronize the files stored in the database with those on the file system, so new and existing fields should still have a value that makes sense from your base media directory.

If you're using South, the initial model migrations will scan through all existing models for FileFields or ImageFields and will automatically load them into the database.

If for any reason you want to re-run this bulk import task, run:

python manage.py database_files_load

Additionally, if you want to export all files in the database back to the file system, run:

python manage.py database_files_dump

Note, that when a field referencing a file is cleared, the corresponding file in the database and on the file system will not be automatically deleted. To delete all files in the database and file system not referenced by any model fields, run:

python manage.py database_files_cleanup

Settings

  • DB_FILES_AUTO_EXPORT_DB_TO_FS = True|False (default True)

    If true, when a file is uploaded or read from the database, a copy will be exported to your media directory corresponding to the FileField's upload_to path, just as it would with the default Django file storage.

    If false, the file will only exist in the database.

  • DATABASE_FILES_URL_METHOD = URL_METHOD_1|URL_METHOD_2 (default URL_METHOD_1)

    Defines the method to use when rendering the web-accessible URL for a file.

    If URL_METHOD_1, assumes all files have been exported to the filesystem and uses the path corresponding to your settings.MEDIA_URL.

    If URL_METHOD_2, uses the URL bound to the database_file view to dynamically lookup and serve files from the filesystem or database.

    In this case, you will also need to updates your urls.py to include the view that serves the files:

      urlpatterns = patterns('',
          # ... the rest of your URLconf goes here ...
    
          # Serve Database Files directly
          url(r'', include('database_files.urls')),
      )
    

Development

Tests require the Python development headers to be installed, which you can install on Ubuntu with:

sudo apt-get install python-dev python3-dev python3.4-dev

To run unittests across multiple Python versions, install:

sudo apt-get install python3.4-minimal python3.4-dev python3.5-minimal python3.5-dev

Note, you may need to enable an additional repository to provide these packages.

To run all tests:

export TESTNAME=; tox

To run tests for a specific environment (e.g. Python 2.7 with Django 1.4):

export TESTNAME=; tox -e py27-django15

To run a specific test:

export TESTNAME=.test_adding_file; tox -e py27-django15

To build and deploy a versioned package to PyPI, verify all unittests are passing, and then run:

python setup.py sdist
python setup.py sdist upload

Metadata

Release files for django-database-files-3000 1.0.5

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-database-files-3000 1.0.5
File Size Uploaded
django-database-files-3000-1.0.5.tar.gz 24.9 kB Details

Release files / django-database-files-3000-1.0.5.tar.gz

Download URL django-database-files-3000-1.0.5.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bd3268f196a62bf67b5a1c645e8a04cb8756184fc55b96a46b1f46ae7f54e537
BLAKE2b-256 checksum
How to use checksums
98f736b164c0a1a4442cdaf38076ec64f08e368991ad10040af446b3ad41185a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0.5 This release

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

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