Skip to main content

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 https://pypi.org/project/python-resize-image/

Made by Axiacore.

Release files for ax3-model-extras 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ax3-model-extras 1.5.0
File Size Uploaded
AX3 model extras-1.5.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ax3-model-extras 1.5.0
File Interpreter ABI Platform
AX3_model_extras-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / AX3 model extras-1.5.0.tar.gz

Download URL AX3 model extras-1.5.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d8ed5ddd63dd18ef04681bf6e3638531eca55c2ece8cc0bc86d254ec782a2c09
BLAKE2b-256 checksum
How to use checksums
d8a106db6b809abeb05d86b4bd4017dfb34f2471d1b97eacb446909190bb5a84
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.10

Release files / AX3_model_extras-1.5.0-py3-none-any.whl

Download URL AX3_model_extras-1.5.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e3a4592a1619daa351e3f02a80d5129e9cd54729e522eb165048f7997aa3490b
BLAKE2b-256 checksum
How to use checksums
504e103bb6eab7d3bc397a3b69078bd52ce87a3a31fd881c5521fec0528ef5a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.10

Release history Release notifications | RSS feed

2.0.1

3 release files

2.0.0

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

This release

1.5.0 This release

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page