Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/modbender/easy-thumbnails-rest
Easy Thumbnails Fields for Django Rest API
https://github.com/modbender/easy-thumbnails-rest
django django-rest-framework easy-thumbnails python rest rest-api
Last synced: about 1 month ago
JSON representation
Easy Thumbnails Fields for Django Rest API
- Host: GitHub
- URL: https://github.com/modbender/easy-thumbnails-rest
- Owner: modbender
- License: bsd-3-clause
- Created: 2020-05-18T20:10:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-09T05:28:29.000Z (3 months ago)
- Last Synced: 2024-11-10T10:51:57.437Z (about 2 months ago)
- Topics: django, django-rest-framework, easy-thumbnails, python, rest, rest-api
- Language: Python
- Homepage: https://pypi.org/project/easy-thumbnails-rest/
- Size: 64.5 KB
- Stars: 7
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Easy Thumbnails Rest
[![Downloads](https://pepy.tech/badge/easy-thumbnails-rest)](https://pepy.tech/project/easy-thumbnails-rest)
[![Downloads](https://pepy.tech/badge/easy-thumbnails-rest/month)](https://pepy.tech/project/easy-thumbnails-rest/month)
[![Downloads](https://pepy.tech/badge/easy-thumbnails-rest/week)](https://pepy.tech/project/easy-thumbnails-rest/week)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](https://github.com/SmileyChris/easy-thumbnails).Please make sure to have `THUMBNAIL_ALIASES` defined in `settings.py`.
If not added, please check [Easy Thumbnails Docs](https://easy-thumbnails.readthedocs.io/en/latest/usage/#thumbnail-aliases) 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](https://github.com/SmileyChris/easy-thumbnails#fields)
Example `settings.THUMBNAIL_ALIASES`
```python
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:
```python
from rest_framework import serializers
from easy_thumbnails_rest.serializers import ThumbnailerSerializerclass 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](https://easy-thumbnails.readthedocs.io/en/latest/usage/#thumbnail-aliases)
Example:
```python
from rest_framework import serializers
from easy_thumbnails_rest.serializers import ThumbnailerListSerializerclass 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](https://easy-thumbnails.readthedocs.io/en/latest/usage/#thumbnail-aliases)
Example:
```python
from rest_framework import serializers
from easy_thumbnails_rest.serializers import ThumbnailerJSONSerializerclass 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.