Easy Thumbnails Fields for Django Rest API
Project description
Easy Thumbnails Rest
Easy Thumbnails Fields for Django Rest API Framework
Installation
pip install easy-thumbnails-rest
Tested on Django 2.2, 3.1, 3.2
Usage
This package is an extension for easy-thumbnails.
Please make sure to have THUMBNAIL_ALIASES
defined in settings.py
.
If not added, please check Easy Thumbnails Docs to add it.
To use the serializer fields provided by this package you need to have your image fields defined as provided here: easy-thumbnails fields
Example settings.THUMBNAIL_ALIASES
THUMBNAIL_ALIASES = {
'': {
'avatar': {'size': (50, 50), 'crop': True},
},
}
Fields
- ThumbnailerSerializer
- ThumbnailerListSerializer
- ThumbnailerJSONSerializer
ThumbnailerSerializer
You can use ThumbnailerSerializer
to get image's predefined alias. You need to pass argument alias
with value as one of the aliases name defined in THUMBNAIL_ALIASES
Example:
from rest_framework import serializers
from easy_thumbnails_rest.serializers import ThumbnailerSerializer
class ExampleSerializer(serializers.ModelSerializer):
image = ThumbnailerSerializer(alias='avatar')
class Meta:
model = ExampleModel
fields = '__all__'
From the above example the field image
will contain string value of alias image url.
ThumbnailerListSerializer
You can use ThumbnailerListSerializer
to get image's predefined alias image list. You need to pass argument alias
with value as one of the target's in THUMBNAIL_ALIASES
.
If you don't understand where to find target, please see the structure of the THUMBNAIL_ALIASES
in Easy Thumbnails Docs
Example:
from rest_framework import serializers
from easy_thumbnails_rest.serializers import ThumbnailerListSerializer
class ExampleSerializer(serializers.ModelSerializer):
image = ThumbnailerListSerializer(alias='target')
class Meta:
model = ExampleModel
fields = '__all__'
From the above example the field image
will contain list of all aliased image urls under the given target.
ThumbnailerJSONSerializer
You can use ThumbnailerJSONSerializer
to get image's predefined alias image list. You need to pass argument alias
with value as one of the target's in THUMBNAIL_ALIASES
.
If you don't understand where to find target, please see the structure of the THUMBNAIL_ALIASES
in Easy Thumbnails Docs
Example:
from rest_framework import serializers
from easy_thumbnails_rest.serializers import ThumbnailerJSONSerializer
class ExampleSerializer(serializers.ModelSerializer):
image = ThumbnailerJSONSerializer(alias='target')
class Meta:
model = ExampleModel
fields = '__all__'
From the above example the field image
will contain list of key-value pair where key's are the alias under the given target and values are the respective image url.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file easy-thumbnails-rest-1.1.4.tar.gz
.
File metadata
- Download URL: easy-thumbnails-rest-1.1.4.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1c619e812c57a85932f1f3b061667bc4b9002528056d5d8fa4c99e4c567385a |
|
MD5 | 4620fc372c81d7a21edd5a7d6350d0a2 |
|
BLAKE2b-256 | 83de13e812ecede45b44f0ca3383e49e72dcf7a98ad095603f94a67e22e151c4 |
File details
Details for the file easy_thumbnails_rest-1.1.4-py3-none-any.whl
.
File metadata
- Download URL: easy_thumbnails_rest-1.1.4-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22d2789bb3f9a26d949e7f292a23f02a5feb68ef8badcb53bac1fd1466322d60 |
|
MD5 | c64bbd7af67c84206487847feb73a410 |
|
BLAKE2b-256 | b2ecc390f9e58e0924ae575abf7483fcb9be93fedf97130759e0b8314f4aad2e |