AX3 Model Extras
Installation
AX3 Model Extras is easy to install from the PyPI package:
$ 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:
INSTALLED_APPS = (
...
'ax3_model_extras',
...
)
Validate image size
If you want to validate the dimension and file size for images:
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
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:
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:
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:
image = OptimizedImageField(
optimized_image_output_size=(1920, 800),
)
If want to set the size of the image using the 'thumbnail' method do:
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):
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):
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
Releasing a new version
Make sure you have an API Token for PyPI: https://pypi.org/help/#apitoken
Make sure you increase the version number and create a git tag:
$ python3 -m pip install --user --upgrade setuptools wheel twine
$ ./release.sh
Made by Axiacore.
Metadata
Release files for ax3-model-extras 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ax3_model_extras-2.0.1.tar.gz | 7.4 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ax3_model_extras-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
| AX3_model_extras-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.0 kB
Release files / ax3_model_extras-2.0.1.tar.gz
| Download URL | ax3_model_extras-2.0.1.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5935406a52b2578df30e252c4f50bc96efb2a20a1c982e48cd5b95856e8a62c0
|
|
BLAKE2b-256 checksum How to use checksums |
c9df8ef01edfc90b9dba67346fb06cae48427a48d52cbc55fca0185cf9bfc4c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / ax3_model_extras-2.0.1-py3-none-any.whl
| Download URL | ax3_model_extras-2.0.1-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58284aca826db1ddaf6c73c85dcb768581c665346704cbecf06107550c581eb9
|
|
BLAKE2b-256 checksum How to use checksums |
91394e04becc93b53f88ed12312b30391cead43c5150f769685861473568c4f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / AX3_model_extras-2.0.1-py3-none-any.whl
| Download URL | AX3_model_extras-2.0.1-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c1ef2d6438ed53a055c2170c646f01b560641d3f0b1d72ba17fc69740360ea4
|
|
BLAKE2b-256 checksum How to use checksums |
910911e28384d74a6d5f928ca0a6478d050fbf97586ca8d8d568c0d527762608
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|