This Python package provides a Django storage implementation that uses a single database table.
Django developers may find this package may be most helpful for use in their test and prototype environments.
This package may also be useful in launching small-scale projects/environments quickly without needing additional infrastructure setup.
**WARNING:** For production applications, please consider using a CDN instead of this package, as it is not a good practice to serve files from a database. Website performance will suffer! Please see the section "Alternatives" below for performant and scalable storage options.
# Features / Benefits
* Easy to install and configure.
* Serve files properly when there are multiple django servers under a load balancer.
* Files persist in database when application server is rebuilt (as long as database is not hosted on the application server).
* In unit testing scenarios, created files can be automatically "rolled back" out of existence if the unit test uses a transaction, which is how `django.test.TestCase` works.
# Installation
```shell
pip install django-single-table-db-storage
```
# Setup
In your django settings file, add `'django_single_table_db_storage'` to `INSTALLED_APPS`.
```python3
INSTALLED_APPS = [
...
'django_single_table_db_storage',
...
]
```
Also in your django settings file, set up the default storage. It is recommended that you add a TODO to remind yourself to use a better storage in the future.
```python
# TODO: As this project scales, a CDN or S3-compatible storage for production
# might be a better solution.
DEFAULT_FILE_STORAGE = 'django_single_table_db_storage.storage.SingleTableDbFileStorage'
```
In your django settings file, you should determine the default accesibility of the files that are uploaded.
```python
DJANGO_SINGLE_TABLE_DEFAULT_PUBLIC = True # or set it to False. The default is False.
```
Mount the URLs where you want in your `urls.py` file.
```python
urlpatterns = [
...
path('files/', include('django_single_table_db_storage.urls')),
....
]
```
Run the database migrations to create the table.
```shell
./manage.py migrate
```
...And now your environment is set to use the file storage.
# Alternatives
You can find other file storage alternatives for Django here:
https://djangopackages.org/grids/g/storage-backends/
This package contains a similar and possibly better implementation to this library, depending on your use case and license that you prefer:
https://github.com/kimetrica/django-binary-database-files/
Raw data
{
"_id": null,
"home_page": "https://github.com/waterimp/django-single-table-db-storage",
"name": "django-single-table-db-storage",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "django storage database",
"author": "Lee Bush",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/94/66/acab7aba70ced24cce7da9abebdd9f5a48f1257acc8c06c89c469d463283/django-single-table-db-storage-0.1.2.tar.gz",
"platform": null,
"description": "This Python package provides a Django storage implementation that uses a single database table.\n\nDjango developers may find this package may be most helpful for use in their test and prototype environments.\nThis package may also be useful in launching small-scale projects/environments quickly without needing additional infrastructure setup.\n\n**WARNING:** For production applications, please consider using a CDN instead of this package, as it is not a good practice to serve files from a database. Website performance will suffer! Please see the section \"Alternatives\" below for performant and scalable storage options.\n\n# Features / Benefits\n\n* Easy to install and configure.\n* Serve files properly when there are multiple django servers under a load balancer.\n* Files persist in database when application server is rebuilt (as long as database is not hosted on the application server).\n* In unit testing scenarios, created files can be automatically \"rolled back\" out of existence if the unit test uses a transaction, which is how `django.test.TestCase` works.\n\n\n# Installation\n\n\n```shell\npip install django-single-table-db-storage\n```\n\n# Setup\n\nIn your django settings file, add `'django_single_table_db_storage'` to `INSTALLED_APPS`.\n\n```python3\nINSTALLED_APPS = [\n ...\n 'django_single_table_db_storage',\n ...\n]\n```\n\nAlso in your django settings file, set up the default storage. It is recommended that you add a TODO to remind yourself to use a better storage in the future.\n\n```python\n# TODO: As this project scales, a CDN or S3-compatible storage for production\n# might be a better solution.\nDEFAULT_FILE_STORAGE = 'django_single_table_db_storage.storage.SingleTableDbFileStorage'\n```\n\nIn your django settings file, you should determine the default accesibility of the files that are uploaded.\n\n\n```python\nDJANGO_SINGLE_TABLE_DEFAULT_PUBLIC = True # or set it to False. The default is False.\n\n```\n\nMount the URLs where you want in your `urls.py` file.\n\n```python\nurlpatterns = [\n ... \n path('files/', include('django_single_table_db_storage.urls')),\n ....\n]\n```\n\nRun the database migrations to create the table.\n\n```shell\n./manage.py migrate\n```\n\n...And now your environment is set to use the file storage.\n\n\n# Alternatives\n\nYou can find other file storage alternatives for Django here:\n\nhttps://djangopackages.org/grids/g/storage-backends/\n\n\nThis package contains a similar and possibly better implementation to this library, depending on your use case and license that you prefer:\n\nhttps://github.com/kimetrica/django-binary-database-files/\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Provides a Django storage implementation that uses a single database table.",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/waterimp/django-single-table-db-storage"
},
"split_keywords": [
"django",
"storage",
"database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6e578ee3b7db6a82754a2ed4e1dc88b57c87a57d01773b1c60f265b54d914942",
"md5": "ba9af26c7d074830c1e2428d0e418b82",
"sha256": "0aa01fc408199caed206ad5a635923ff6cdb0bd6a5a60f0befc55be6b8c9264f"
},
"downloads": -1,
"filename": "django_single_table_db_storage-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ba9af26c7d074830c1e2428d0e418b82",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 6131,
"upload_time": "2023-09-11T08:31:08",
"upload_time_iso_8601": "2023-09-11T08:31:08.213373Z",
"url": "https://files.pythonhosted.org/packages/6e/57/8ee3b7db6a82754a2ed4e1dc88b57c87a57d01773b1c60f265b54d914942/django_single_table_db_storage-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9466acab7aba70ced24cce7da9abebdd9f5a48f1257acc8c06c89c469d463283",
"md5": "664f9c15c2a811720c623ba88ae40f3b",
"sha256": "7832ec3338014782ef5a1e07b640425f6ee76c6d529fa7321b814b17e255f988"
},
"downloads": -1,
"filename": "django-single-table-db-storage-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "664f9c15c2a811720c623ba88ae40f3b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 4859,
"upload_time": "2023-09-11T08:31:09",
"upload_time_iso_8601": "2023-09-11T08:31:09.782168Z",
"url": "https://files.pythonhosted.org/packages/94/66/acab7aba70ced24cce7da9abebdd9f5a48f1257acc8c06c89c469d463283/django-single-table-db-storage-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-11 08:31:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "waterimp",
"github_project": "django-single-table-db-storage",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-single-table-db-storage"
}