django-blob-storage


Namedjango-blob-storage JSON
Version 0.2.2 PyPI version JSON
download
home_page
Summary
upload_time2023-05-22 09:50:50
maintainer
docs_urlNone
authoralex
requires_python>=3.9,<4.0
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-blob-storage

This is a fork from django-db-storage2

## Overview

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.

.. \_StackExchange post: http://programmers.stackexchange.com/questions/150669/is-it-a-bad-practice-to-store-large-files-10-mb-in-a-database

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
-   only db files need to be backed up

## Requirements

-   Python (3.5+)
-   Django (3.2+)

## Installation

Installation using pip::

    $ pip install django-blob-storage

Update `settings.py`

```python

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

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

    # Optionally for tracking file accesses (currently over view)
    # DJANGO_DBFILE_TRACK_ACCESSED=True
    # Optionally set another db than default
    # DJANGO_DBFILE_DB = "foo"

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

Update `urls.py`

```python

    urlpatterns = [
        ...
        # dbstorage
        path("", include("dbstorage.urls")),
    ]
```

Run database migrations (done automatically, when included as app)

```sh

env DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH="." poetry run django-admin migrate


```

## How to Use

No modification are needed for models to work properly.

```python

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)
```

## Bugs?

Create an issue at https://github.com/devkral/django-blob-storage/issues

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "django-blob-storage",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "alex",
    "author_email": "devkral@web.de",
    "download_url": "https://files.pythonhosted.org/packages/2b/21/4f62515414984d88521ef2216c5c94927efb01b4632c5cea9c3fa4af3c40/django_blob_storage-0.2.2.tar.gz",
    "platform": null,
    "description": "# django-blob-storage\n\nThis is a fork from django-db-storage2\n\n## Overview\n\nWarning: 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.\n\n.. \\_StackExchange post: http://programmers.stackexchange.com/questions/150669/is-it-a-bad-practice-to-store-large-files-10-mb-in-a-database\n\nThis 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:\n\n-   no changes needed to existing models, it just works (and if it doesn't, open a ticket!)\n-   django-admin is implemented and can be used to search, upload, download and manage files\n-   100% code coverage with unit tests\n-   only db files need to be backed up\n\n## Requirements\n\n-   Python (3.5+)\n-   Django (3.2+)\n\n## Installation\n\nInstallation using pip::\n\n    $ pip install django-blob-storage\n\nUpdate `settings.py`\n\n```python\n\n    # Add 'dbstorage' to INSTALLED_APPS\n    INSTALLED_APPS = [\n        'dbstorage',\n    ]\n\n    # Optionally set DEFAULT_FILE_STORAGE\n    DEFAULT_FILE_STORAGE = 'dbstorage.storage.DBStorage'\n\n    # Optionally for tracking file accesses (currently over view)\n    # DJANGO_DBFILE_TRACK_ACCESSED=True\n    # Optionally set another db than default\n    # DJANGO_DBFILE_DB = \"foo\"\n\n    # Choose a root url for uploaded files\n    MEDIA_URL = '/media/'\n```\n\nUpdate `urls.py`\n\n```python\n\n    urlpatterns = [\n        ...\n        # dbstorage\n        path(\"\", include(\"dbstorage.urls\")),\n    ]\n```\n\nRun database migrations (done automatically, when included as app)\n\n```sh\n\nenv DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=\".\" poetry run django-admin migrate\n\n\n```\n\n## How to Use\n\nNo modification are needed for models to work properly.\n\n```python\n\ndef user_directory_path(instance, filename):\n    return 'user_{0}/{1}'.format(instance.user.id, filename)\n\nclass MyModel(models.Model):\n\n    file_field1 = models.FileField()\n    file_field2 = models.FileField(upload_to='uploads/%Y/%m/%d/')\n    file_field3 = models.FileField(upload_to=user_directory_path)\n```\n\n## Bugs?\n\nCreate an issue at https://github.com/devkral/django-blob-storage/issues\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "",
    "version": "0.2.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6a136526f907c0f54f58d5228e7689b75ae2d569f85c09c67fc56f1eb2f9a4e1",
                "md5": "5f1808d656dd650978bba26dffe73728",
                "sha256": "9f2eddb68d6b0dafb4a44c3fb1d8acdb5d35ebbc169dfec6a40e380be1941139"
            },
            "downloads": -1,
            "filename": "django_blob_storage-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f1808d656dd650978bba26dffe73728",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 8860,
            "upload_time": "2023-05-22T09:50:49",
            "upload_time_iso_8601": "2023-05-22T09:50:49.407081Z",
            "url": "https://files.pythonhosted.org/packages/6a/13/6526f907c0f54f58d5228e7689b75ae2d569f85c09c67fc56f1eb2f9a4e1/django_blob_storage-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b214f62515414984d88521ef2216c5c94927efb01b4632c5cea9c3fa4af3c40",
                "md5": "d5989da4e5347d2bcb87250735050150",
                "sha256": "9169cea60749947426fa9f7fea462caf7689764b3e90b15a507bbba5bcdb9a2d"
            },
            "downloads": -1,
            "filename": "django_blob_storage-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d5989da4e5347d2bcb87250735050150",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 7102,
            "upload_time": "2023-05-22T09:50:50",
            "upload_time_iso_8601": "2023-05-22T09:50:50.863467Z",
            "url": "https://files.pythonhosted.org/packages/2b/21/4f62515414984d88521ef2216c5c94927efb01b4632c5cea9c3fa4af3c40/django_blob_storage-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-22 09:50:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "django-blob-storage"
}
        
Elapsed time: 0.20207s