An image serializer field for use with sorl and Django REST Framework.
Project description
An image serializer field for use with sorl and Django REST Framework.
Provides an easy way of exposing a scaled version of an image rather than the full-size one, and if you prefer several different versions (thumb, large etc.)
Quick start
Add the HyperlinkedSorlImageField to your serializer class.
Specify the image dimensions and cropping options that the REST API should use.
Example usage
# urls.py
from django.conf.urls import url, include
from models import TestModel
from rest_framework import routers, serializers, viewsets
from sorl_thumbnail_serializer.fields import HyperlinkedSorlImageField
class TestModelSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = TestModel
# A thumbnail image, sorl options and read-only
thumbnail = HyperlinkedSorlImageField(
'128x128',
options={"crop": "center"},
source='image',
read_only=True
)
# A larger version of the image, allows writing
image = HyperlinkedSorlImageField('1024')
class TestModelViewSet(viewsets.ModelViewSet):
queryset = TestModel.objects.all()
serializer_class = TestModelSerializer
router = routers.DefaultRouter()
router.register(r'test_models', TestModelViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
]
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
Close
Hashes for sorl-thumbnail-serializer-field-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebf042344db537b4605963461e5916c49a39da63973992dea5f394e724145d43 |
|
MD5 | 9c66fc3eec01428a8bcb59af291956ae |
|
BLAKE2b-256 | 590a909b8eeddb7dbc245acad8339844e9a97bc80de938ff34ef411f51ace26d |