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
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
ThumbnailerJSONSerializer (formerly 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 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
Hashes for easy-thumbnails-rest-1.0.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7979b51a313ba5e06f2ce2d3ec1d7b33ee121537b2d0c1b9519c0d9c8a6922c |
|
MD5 | da79f116f1d2de299d99bc641215dfbf |
|
BLAKE2b-256 | 01297d88ce590dff782e1066e0574f169ca43badf4d52291192a9dc1d01eaa84 |
Hashes for easy_thumbnails_rest-1.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f00c5a16c9edc8b0812b5b291ab8ffba232e9fa2e3e49d698301a6b5be17207e |
|
MD5 | 244fa7bd499566282697c5d5d0baeeb1 |
|
BLAKE2b-256 | 4ca2641493a69e0c6350f9e55dbd38aaa7334a63a49ac5f0fd0b6b6b9c372175 |