Easy Thumbnails Fields for Django Rest API
Project description
Easy Thumbnails Fields for Django Rest API Framework
Installation
Run pip install easy-thumbnails-rest.
[OPTIONAL] Add easy_thumbnails_rest to INSTALLED_APPS
INSTALLED_APPS = ( ... 'easy_thumbnails', 'easy_thumbnails_rest' #optional )
Usage
Remember that this app needs THUMBNAIL_ALIASES to be defined in settings.py and the field that you need to serialize should be of type ThumbnailerImageField (or ThumbnailerField) to work.
If not yet added, please check Easy Thumbnails Docs to add it.
Example settings.THUMBNAIL_ALIASES
THUMBNAIL_ALIASES = { '': { 'avatar': {'size': (50, 50), 'crop': True}, }, }
Fields:
ThumbnailerSerializer
ThumbnailerListSerializer
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 values 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='') class Meta: model = ExampleModel fields = '__all__'
From the above example the field image will contain JSON value having all aliased image urls under a target.
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
Hashes for easy-thumbnails-rest-1.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49fcf5b64a418751b8a1209e9ec130f441e48cf911d7439de50521c2e2fa13a1 |
|
MD5 | 27c88ce1ed14e77d422b840354f530fb |
|
BLAKE2b-256 | ef1bec05d021bdd341502a705115804d79c4c60d0572e3f58011d31c492e8293 |
Hashes for easy_thumbnails_rest-1.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 892cb1b763247c2b00073556e1f3780d58012178ea825252b3f9ea3868170f39 |
|
MD5 | fc5e82c99f2f4051722024badb295a33 |
|
BLAKE2b-256 | 2f6e3bcf2ef57e1dd33cba089b3c1e96541823063463947b183e62e4aae8b671 |