# AX3 Model Extras
## Installation
AX3 Model Extras is easy to install from the PyPI package:
```bash
$ pip install ax3-model-extras
```
To enable ax3_model_extras in your project you need to add it to INSTALLED_APPS in your projects settings.py file:
```python
INSTALLED_APPS = (
...
'ax3_model_extras',
...
)
```
## Validate image size
If you want to validate the dimension and file size for images:
```python
from ax3_model_extras.validators import FileSizeValidator, ImageDimensionValidator
class Post(models.Model):
title = models.CharField()
slug = models.SlugField()
image = models.ImageField(
validators=[ImageDimensionValidator([1920, 800]), FileSizeValidator(350)],
help_text='JPG. 1920x800px. 350kb max.',
)
```
If you want to validate one dimension, you have to send the other dimension with 0
```python
from ax3_model_extras.validators import FileSizeValidator, ImageDimensionValidator
class Post(models.Model):
title = models.CharField()
slug = models.SlugField()
image = models.ImageField(
validators=[ImageDimensionValidator([1920, 0]), FileSizeValidator(350)],
help_text='JPG. width=1920px. 350kb max.',
)
```
## Improve file storage
If you want to improve the local file storage or use S3 upload:
```python
from ax3_model_extras.storages import get_storage, get_upload_path
class Post(models.Model):
title = models.CharField()
slug = models.SlugField()
image = models.ImageField(
upload_to=get_upload_path,
storage=get_storage(),
)
```
## Optimize images before upload them.
Use as:
```python
from ax3_model_extras.fields import OptimizedImageField
class Post(models.Model):
title = models.CharField()
slug = models.SlugField()
image = OptimizedImageField()
```
If want to set the size of the image using the 'cover' method do:
```python
image = OptimizedImageField(
optimized_image_output_size=(1920, 800),
)
```
If want to set the size of the image using the 'thumbnail' method do:
```python
image = OptimizedImageField(
optimized_image_output_size=(1920, 800),
optimized_image_resize_method='thumbnail',
)
```
If want to restrict the file format do (If not set it supports JPEG, PNG and GIF):
```python
image = OptimizedImageField(
optimized_image_output_size=(1920, 800),
optimized_image_resize_method='thumbnail',
optimized_file_formats=['PNG'],
)
```
If want to specific quality of the image (If not set it default = 75):
```python
image = OptimizedImageField(
optimized_image_output_size=(1920, 800),
optimized_image_resize_method='thumbnail',
optimized_file_formats=['PNG'],
optimized_image_quality=85.5,
)
```
Resize is done using [python-resize-image](https://pypi.org/project/python-resize-image/)
## Releasing a new version
Make sure you increase the version number and create a git tag:
```bash
$ python3 -m pip install --user --upgrade setuptools wheel twine
$ ./release.sh
```
Made by [Axiacore](https://axiacore.com).
Raw data
{
"_id": null,
"home_page": "https://github.com/axiacore/ax3-model-extras",
"name": "AX3-model-extras",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Axiacore",
"author_email": "info@axiacore.com",
"download_url": "https://files.pythonhosted.org/packages/93/f0/0fca3798b3e528361aafdd7e885ff5bf5c9df30c1c391d724e605feb8b76/AX3%20model%20extras-2.0.0.tar.gz",
"platform": null,
"description": "# AX3 Model Extras\n\n## Installation\n\nAX3 Model Extras is easy to install from the PyPI package:\n\n```bash\n$ pip install ax3-model-extras\n```\n\nTo enable ax3_model_extras in your project you need to add it to INSTALLED_APPS in your projects settings.py file:\n\n```python\nINSTALLED_APPS = (\n ...\n 'ax3_model_extras',\n ...\n)\n```\n\n## Validate image size\n\nIf you want to validate the dimension and file size for images:\n\n```python\nfrom ax3_model_extras.validators import FileSizeValidator, ImageDimensionValidator\n\n\nclass Post(models.Model):\n title = models.CharField()\n\n slug = models.SlugField()\n\n image = models.ImageField(\n validators=[ImageDimensionValidator([1920, 800]), FileSizeValidator(350)],\n help_text='JPG. 1920x800px. 350kb max.',\n )\n```\n\nIf you want to validate one dimension, you have to send the other dimension with 0\n\n```python\nfrom ax3_model_extras.validators import FileSizeValidator, ImageDimensionValidator\n\n\nclass Post(models.Model):\n title = models.CharField()\n\n slug = models.SlugField()\n\n image = models.ImageField(\n validators=[ImageDimensionValidator([1920, 0]), FileSizeValidator(350)],\n help_text='JPG. width=1920px. 350kb max.',\n )\n```\n\n## Improve file storage\n\nIf you want to improve the local file storage or use S3 upload:\n\n```python\nfrom ax3_model_extras.storages import get_storage, get_upload_path\n\n\nclass Post(models.Model):\n title = models.CharField()\n\n slug = models.SlugField()\n\n image = models.ImageField(\n upload_to=get_upload_path,\n storage=get_storage(),\n )\n```\n\n## Optimize images before upload them.\n\nUse as:\n\n```python\nfrom ax3_model_extras.fields import OptimizedImageField\n\n\nclass Post(models.Model):\n title = models.CharField()\n\n slug = models.SlugField()\n\n image = OptimizedImageField()\n\n```\n\nIf want to set the size of the image using the 'cover' method do:\n\n```python\nimage = OptimizedImageField(\n optimized_image_output_size=(1920, 800),\n)\n```\n\nIf want to set the size of the image using the 'thumbnail' method do:\n\n```python\nimage = OptimizedImageField(\n optimized_image_output_size=(1920, 800),\n optimized_image_resize_method='thumbnail',\n)\n```\n\nIf want to restrict the file format do (If not set it supports JPEG, PNG and GIF):\n\n```python\nimage = OptimizedImageField(\n optimized_image_output_size=(1920, 800),\n optimized_image_resize_method='thumbnail',\n optimized_file_formats=['PNG'],\n)\n```\n\nIf want to specific quality of the image (If not set it default = 75):\n\n```python\nimage = OptimizedImageField(\n optimized_image_output_size=(1920, 800),\n optimized_image_resize_method='thumbnail',\n optimized_file_formats=['PNG'],\n optimized_image_quality=85.5,\n)\n```\n\nResize is done using [python-resize-image](https://pypi.org/project/python-resize-image/)\n\n## Releasing a new version\n\nMake sure you increase the version number and create a git tag:\n\n```bash\n$ python3 -m pip install --user --upgrade setuptools wheel twine\n$ ./release.sh\n```\n\nMade by [Axiacore](https://axiacore.com).\n",
"bugtrack_url": null,
"license": "",
"summary": "Django app extras for AX3 models",
"version": "2.0.0",
"project_urls": {
"Homepage": "https://github.com/axiacore/ax3-model-extras"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c0e58144c1c2a295e80eecfa614d88906227e1bfc747a4fcc59e22837b317d1e",
"md5": "0e8c9549893284ea43ab0f8eb30841d9",
"sha256": "322d288633ffc3740273dfc27f589aaacbf7682050d4e1c3bd9b671071af9df0"
},
"downloads": -1,
"filename": "AX3_model_extras-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0e8c9549893284ea43ab0f8eb30841d9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8139,
"upload_time": "2023-07-05T22:07:20",
"upload_time_iso_8601": "2023-07-05T22:07:20.949331Z",
"url": "https://files.pythonhosted.org/packages/c0/e5/8144c1c2a295e80eecfa614d88906227e1bfc747a4fcc59e22837b317d1e/AX3_model_extras-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "93f00fca3798b3e528361aafdd7e885ff5bf5c9df30c1c391d724e605feb8b76",
"md5": "49e317432695e620d2f26aa236b6b0e6",
"sha256": "5a5457842e09ec788f7ee9f5c2b958fae243feb5639028038185384b0e5dfdea"
},
"downloads": -1,
"filename": "AX3 model extras-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "49e317432695e620d2f26aa236b6b0e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6412,
"upload_time": "2023-07-05T22:07:22",
"upload_time_iso_8601": "2023-07-05T22:07:22.390552Z",
"url": "https://files.pythonhosted.org/packages/93/f0/0fca3798b3e528361aafdd7e885ff5bf5c9df30c1c391d724e605feb8b76/AX3%20model%20extras-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-05 22:07:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "axiacore",
"github_project": "ax3-model-extras",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "ax3-model-extras"
}