django-dbfiles


Namedjango-dbfiles JSON
Version 3.0.0 PyPI version JSON
download
home_pageNone
SummaryDjango storage backend for storing files in your database.
upload_time2024-07-22 17:41:12
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseBSD
keywords database django files storage
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-dbfiles

A fork of [django-db-storage](https://github.com/derekkwok/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](http://programmers.stackexchange.com/questions/150669/is-it-a-bad-practice-to-store-large-files-10-mb-in-a-database) 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](http://i.imgur.com/4g9tmEZt.png)
![Admin Edit](http://i.imgur.com/A2F8xlrt.png)

## Requirements

* Python 3.8 or above
* Django 4.2 or above

## Installation

Installation using pip:

```
pip install django-dbfiles
```

Update `settings.py`:

```python
# 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`:

```python
urlpatterns = [
    ...
    dbfiles_url(),
]
```

Run database migrations:

```
python manage.py 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)
```

## 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:

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

## Bugs?

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-dbfiles",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "database, django, files, storage",
    "author": null,
    "author_email": "Dan Watson <watsond@imsweb.com>",
    "download_url": "https://files.pythonhosted.org/packages/f4/18/b67bf90d3bc49a38fd9eba63373dd61c8ab45367195d6ef2836f8d9144b4/django_dbfiles-3.0.0.tar.gz",
    "platform": null,
    "description": "# django-dbfiles\n\nA fork of [django-db-storage](https://github.com/derekkwok/django-db-storage), updated for modern versions of Django (and renamed for inclusion in PyPI).\n\n## Overview\n\n*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](http://programmers.stackexchange.com/questions/150669/is-it-a-bad-practice-to-store-large-files-10-mb-in-a-database) for more information.\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\n![Admin List](http://i.imgur.com/4g9tmEZt.png)\n![Admin Edit](http://i.imgur.com/A2F8xlrt.png)\n\n## Requirements\n\n* Python 3.8 or above\n* Django 4.2 or above\n\n## Installation\n\nInstallation using pip:\n\n```\npip install django-dbfiles\n```\n\nUpdate `settings.py`:\n\n```python\n# Add 'dbfiles' to INSTALLED_APPS\nINSTALLED_APPS = [\n    'dbfiles',\n]\n\n# Optionally set DEFAULT_FILE_STORAGE\nDEFAULT_FILE_STORAGE = 'dbfiles.storage.DBStorage'\n\n# Choose a root url for uploaded files\nMEDIA_URL = '/media/'\n```\n\nUpdate `urls.py`:\n\n```python\nurlpatterns = [\n    ...\n    dbfiles_url(),\n]\n```\n\nRun database migrations:\n\n```\npython manage.py migrate\n```\n\n## How to Use\n\nNo modification are needed for models to work properly.\n\n```python\ndef user_directory_path(instance, filename):\n    return 'user_{0}/{1}'.format(instance.user.id, filename)\n\nclass MyModel(models.Model):\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## Moving from django-db-storage?\n\nIf 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:\n\n```sql\nUPDATE django_migrations SET app = 'dbfiles' WHERE app = 'dbstorage';\n```\n\n## Bugs?\n\nCreate an issue at https://github.com/imsweb/django-dbfiles/issues\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Django storage backend for storing files in your database.",
    "version": "3.0.0",
    "project_urls": {
        "Homepage": "https://github.com/imsweb/django-dbfiles"
    },
    "split_keywords": [
        "database",
        " django",
        " files",
        " storage"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f5a44ea0727789902cd7a9fa2247513476306d8098f26265c83ddef7d0bb9d6",
                "md5": "3d4d0bc994943d8d0b7352d3f46abf3d",
                "sha256": "7c949e1b1aa784306de3d80d3af802fb1788c36ef6d106de2ad63ad3e46f781c"
            },
            "downloads": -1,
            "filename": "django_dbfiles-3.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d4d0bc994943d8d0b7352d3f46abf3d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 10680,
            "upload_time": "2024-07-22T17:41:10",
            "upload_time_iso_8601": "2024-07-22T17:41:10.951749Z",
            "url": "https://files.pythonhosted.org/packages/9f/5a/44ea0727789902cd7a9fa2247513476306d8098f26265c83ddef7d0bb9d6/django_dbfiles-3.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f418b67bf90d3bc49a38fd9eba63373dd61c8ab45367195d6ef2836f8d9144b4",
                "md5": "68fecfa9481ba62297c1f30e92311638",
                "sha256": "df5cb13fb7f388896fd336bedc5798f26d84fec4a19f6be59eb82a2a0fd8f4c8"
            },
            "downloads": -1,
            "filename": "django_dbfiles-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "68fecfa9481ba62297c1f30e92311638",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10466,
            "upload_time": "2024-07-22T17:41:12",
            "upload_time_iso_8601": "2024-07-22T17:41:12.256344Z",
            "url": "https://files.pythonhosted.org/packages/f4/18/b67bf90d3bc49a38fd9eba63373dd61c8ab45367195d6ef2836f8d9144b4/django_dbfiles-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-22 17:41:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "imsweb",
    "github_project": "django-dbfiles",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-dbfiles"
}
        
Elapsed time: 2.14117s