# django-admin-tabs
![PyPI - License](https://img.shields.io/pypi/l/django-admin-tabs)
![Pypi Version](https://img.shields.io/pypi/v/django-admin-tabs.svg)
[![Codecov](https://codecov.io/github/valbertovc/django-admin-tabs/branch/main/graph/badge.svg?token=2R5S5GTS0X)](https://codecov.io/github/valbertovc/django-admin-tabs)
![Building](https://img.shields.io/github/actions/workflow/status/valbertovc/django-admin-tabs/release.yml)
![Python Versions](https://img.shields.io/pypi/pyversions/django-admin-tabs.svg)
![Django Versions](https://img.shields.io/pypi/frameworkversions/django/django-admin-tabs)
It generates dynamically a directory path and a secure file name for Django FileField.
Main options:
- Ready to use generators.
- Generate secure file name without especial characters.
- Generate file name using a uuid value.
- Dynamically generate paths from the model instance.
- Generate paths using Python datetime formats.
## Get started
Install the django-admin-tabs in your virtual environment
```bash
$ pip install django-admin-tabs
```
Import it in your models file and add it as a `upload_to` argument in the `FileField`
```python
# my_app/models.py
from upload_to import UploadTo
from django.db import models
class MyModel(models.Model):
attachment = models.FileField(upload_to=UploadTo("attachments"))
```
The path and file name generated will be like this:
```text
"attachments/the-file-name-uploaded.pdf"
```
## How to use the ready-to-use classes
Consider the scenario below:
```python
import upload_to
from django.db import models
class MyUser(models.Model):
username = models.CharField(...)
avatar = models.FileField(upload_to=<generator>)
instance = MyUser(username='user@email.com')
```
Replace the `<generator>` fragment by the generators as showed below:
#### File in root folder
```python
>>> generator = upload_to.UploadTo()
>>> generator(instance, "file.pdf")
"file.pdf"
```
#### Define a folder structure
```python
>>> generator = upload_to.UploadTo(prefix=["files", "documents"])
>>> generator(instance, "file.pdf")
"files/documents/file.pdf"
```
#### Generate a folder name using datetime formats from Python
```python
>>> generator = upload_to.UploadTo(prefix=["pictures", "%Y"])
>>> generator(instance, "file.png")
"pictures/2023/file.png"
```
#### Replace the file name by an hexadecimal uuid value
```python
# 4. replace file name by a uuid value
>>> generator = upload_to.UuidUploadTo()
>>> generator(instance, "file.pdf")
"b189dfdf25e640b2ba5c497472c20962.pdf"
```
#### Generate the folder path using the instance's attributes
```python
>>> generator = upload_to.AttrUploadTo(attrs=["username"])
>>> generator(instance, "file.pdf")
"useremailcom/file.pdf"
```
#### Generate the folder path using the app_label and the model_name from the instance's meta options
```python
>>> generator = upload_to.ModelUploadTo()
>>> generator(instance, "file.pdf")
"my_app/user/file.pdf"
```
## Customize your upload paths
```python
# my_app/models.py
import upload_to
from django.db import models
def my_upload_generator(instance, filename):
filename = upload_to.uuid_filename(filename)
path = upload_to.options_from_instance(instance)
return upload_to.upload_to(path, filename)
class MyProfile(models.Model):
user = models.OneToOneField(...)
avatar = models.FileField(upload_to=my_upload_generator)
```
## Useful links
1. [Documentation](https://valbertovc.github.io/django-admin-tabs/)
2. [Changelog](https://github.com/valbertovc/django-admin-tabs/releases)
3. [PyPi Page](https://pypi.org/project/django-admin-tabs/)
Raw data
{
"_id": null,
"home_page": "https://github.com/valbertovc/django-admin-tabs",
"name": "django-admin-tabs",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4",
"maintainer_email": "",
"keywords": "django,admin,filter,tabs",
"author": "Valberto Carneiro",
"author_email": "valbertovc@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/54/33/207d310c7184c3e8714c697ada115b159d66a01093ef211caf77280a0e41/django_admin_tabs-0.0.1.tar.gz",
"platform": null,
"description": "# django-admin-tabs\n\n![PyPI - License](https://img.shields.io/pypi/l/django-admin-tabs)\n![Pypi Version](https://img.shields.io/pypi/v/django-admin-tabs.svg)\n[![Codecov](https://codecov.io/github/valbertovc/django-admin-tabs/branch/main/graph/badge.svg?token=2R5S5GTS0X)](https://codecov.io/github/valbertovc/django-admin-tabs)\n![Building](https://img.shields.io/github/actions/workflow/status/valbertovc/django-admin-tabs/release.yml)\n![Python Versions](https://img.shields.io/pypi/pyversions/django-admin-tabs.svg)\n![Django Versions](https://img.shields.io/pypi/frameworkversions/django/django-admin-tabs)\n\nIt generates dynamically a directory path and a secure file name for Django FileField.\n\nMain options:\n- Ready to use generators.\n- Generate secure file name without especial characters.\n- Generate file name using a uuid value.\n- Dynamically generate paths from the model instance.\n- Generate paths using Python datetime formats.\n\n## Get started\nInstall the django-admin-tabs in your virtual environment\n```bash\n$ pip install django-admin-tabs\n```\nImport it in your models file and add it as a `upload_to` argument in the `FileField` \n```python\n# my_app/models.py\nfrom upload_to import UploadTo\nfrom django.db import models\n\n\nclass MyModel(models.Model):\n attachment = models.FileField(upload_to=UploadTo(\"attachments\"))\n```\nThe path and file name generated will be like this:\n```text\n\"attachments/the-file-name-uploaded.pdf\"\n```\n\n## How to use the ready-to-use classes\n\nConsider the scenario below:\n```python\nimport upload_to\nfrom django.db import models\n\n\nclass MyUser(models.Model):\n username = models.CharField(...)\n avatar = models.FileField(upload_to=<generator>)\n\ninstance = MyUser(username='user@email.com')\n```\nReplace the `<generator>` fragment by the generators as showed below:\n#### File in root folder\n```python\n>>> generator = upload_to.UploadTo()\n>>> generator(instance, \"file.pdf\")\n\"file.pdf\"\n\n```\n#### Define a folder structure\n```python\n>>> generator = upload_to.UploadTo(prefix=[\"files\", \"documents\"])\n>>> generator(instance, \"file.pdf\")\n\"files/documents/file.pdf\"\n```\n#### Generate a folder name using datetime formats from Python\n```python\n>>> generator = upload_to.UploadTo(prefix=[\"pictures\", \"%Y\"])\n>>> generator(instance, \"file.png\")\n\"pictures/2023/file.png\"\n```\n#### Replace the file name by an hexadecimal uuid value\n```python\n# 4. replace file name by a uuid value\n>>> generator = upload_to.UuidUploadTo()\n>>> generator(instance, \"file.pdf\")\n\"b189dfdf25e640b2ba5c497472c20962.pdf\"\n```\n#### Generate the folder path using the instance's attributes\n```python\n>>> generator = upload_to.AttrUploadTo(attrs=[\"username\"])\n>>> generator(instance, \"file.pdf\")\n\"useremailcom/file.pdf\"\n```\n#### Generate the folder path using the app_label and the model_name from the instance's meta options\n```python\n>>> generator = upload_to.ModelUploadTo()\n>>> generator(instance, \"file.pdf\")\n\"my_app/user/file.pdf\"\n```\n\n## Customize your upload paths\n\n```python\n# my_app/models.py\nimport upload_to\nfrom django.db import models\n\n\ndef my_upload_generator(instance, filename):\n filename = upload_to.uuid_filename(filename)\n path = upload_to.options_from_instance(instance)\n return upload_to.upload_to(path, filename)\n\nclass MyProfile(models.Model):\n user = models.OneToOneField(...)\n avatar = models.FileField(upload_to=my_upload_generator)\n```\n\n## Useful links\n\n1. [Documentation](https://valbertovc.github.io/django-admin-tabs/)\n2. [Changelog](https://github.com/valbertovc/django-admin-tabs/releases)\n3. [PyPi Page](https://pypi.org/project/django-admin-tabs/)",
"bugtrack_url": null,
"license": "",
"summary": "It generates tabs for Django admin's changelist",
"version": "0.0.1",
"project_urls": {
"Bug Tracker": "https://github.com/valbertovc/django-admin-tabs/issues",
"Changelog": "https://github.com/valbertovc/django-admin-tabs/releases",
"Homepage": "https://valbertovc.github.io/django-admin-tabs/",
"Repository": "https://github.com/valbertovc/django-admin-tabs"
},
"split_keywords": [
"django",
"admin",
"filter",
"tabs"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5a69a80b84a894ae5270d8729fba8d68eb771f288fd68b0072d6dfda45737eea",
"md5": "bbe1187a60cac583729358b04c74620f",
"sha256": "73f08150e857555d91d65746ddddee8cf0dcad1e34f9f49a3b2cde1a390a3d86"
},
"downloads": -1,
"filename": "django_admin_tabs-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bbe1187a60cac583729358b04c74620f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4",
"size": 8574,
"upload_time": "2024-01-15T00:54:53",
"upload_time_iso_8601": "2024-01-15T00:54:53.609619Z",
"url": "https://files.pythonhosted.org/packages/5a/69/a80b84a894ae5270d8729fba8d68eb771f288fd68b0072d6dfda45737eea/django_admin_tabs-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5433207d310c7184c3e8714c697ada115b159d66a01093ef211caf77280a0e41",
"md5": "b6a4fb66eec600910509a7eccc774a62",
"sha256": "85f284af8fcb9b9e8c51de6e35434ce0e2046c494bb748a258783c34bbd0bfa7"
},
"downloads": -1,
"filename": "django_admin_tabs-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "b6a4fb66eec600910509a7eccc774a62",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4",
"size": 6797,
"upload_time": "2024-01-15T00:54:55",
"upload_time_iso_8601": "2024-01-15T00:54:55.411895Z",
"url": "https://files.pythonhosted.org/packages/54/33/207d310c7184c3e8714c697ada115b159d66a01093ef211caf77280a0e41/django_admin_tabs-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-15 00:54:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "valbertovc",
"github_project": "django-admin-tabs",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-admin-tabs"
}