SmartDBStorage is a File Storage for Django that stores files in the database using Django Models.
When the attachments or images are as important as the other data, you may want to store them in the database for better integrity and consistency.
For example, this is specially useful to store original pictures which are displayed using sorl thumbnail.
Advantages : everything at the same place, no more broken links, better flexibility. Disadvantages : performance, overall data usage.
Features
Minimal configuration : just a pluggable Django app.
Django model based : No database to create and setup manually. Uses South.
Files are saved in chunks in order to limit memory usage.
Original file names are preserved : no more logo_1.jpg, logo_2.jpg, logo_3.jpg “behind the scene” renames. (Files are renamed to /some_unique_id/original_file_name.ext)
Files can be extracted to another File Storage when accessed from the web or be served directly from the database. (not recommended, but useful for debugging purposes)
Basic admin for inspection purposes.
Caveats
Django doesn’t support blobs yet (planned in 1.6) so file chunks are saved in base64, which increases the overall storage requirements.
Install
In your settings.py, add 'south' (if you don’t use it already) and 'smartdbstorage' to your INSTALLED_APPS:
INSTALLED_APPS = (
...
'south',
'smartdbstorage'
)
In settings.py, it’s a good idea to set global defaults:
SMARTDBSTORAGE_SERVE_DIRECTLY = False # when accessed from the web files are either served directly or extracted to another file storage SMARTDBSTORAGE_EXTRACTION_STORAGE = DEFAULT_FILE_STORAGE
In your urls.py, add the following:
(r'^some_prefix/', include('smartdbstorage.urls', namespace='smart_db_storage')),
This allows to serve files directly from the database if needed.
Example usage
Simply specify a SmartDBStorage instance where you want to use it:
class Article(models.Model):
text = models.TextField()
image = ImageField(upload_to='articles_images', storage=SmartDBStorage())
You can override defaults like this:
class Article(models.Model):
text = models.TextField()
image = ImageField(upload_to='articles_images', storage=SmartDBStorage(option=dict(extraction_storage=FileSystemStorage())))
Metadata
Release files for django_smartdbstorage 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_smartdbstorage-0.1.1.tar.gz | 6.6 kB | Without provenance | Details |
Release files / django_smartdbstorage-0.1.1.tar.gz
| Download URL | django_smartdbstorage-0.1.1.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b8b94219e6437cd9f58325ee4167ab3e6170a9a37d90b7065b4d9d15dce9c7b
|
|
BLAKE2b-256 checksum How to use checksums |
7430cc6bf1e21ca25f8a916daa87d6ccaad27356f99d08537a0e15143cb0434e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django_smartdbstorage 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.