Skip to content
Permalink
Browse files

Serializing Images with Wagtails ImageRenditionField

  • Loading branch information
KalobTaulien committed Mar 25, 2019
1 parent 2c52d07 commit ec1b75b40d05f8b48b3bcfedfaa762bc751646e1
Showing with 11 additions and 0 deletions.
  1. +11 −0 blog/models.py
@@ -19,6 +19,7 @@
from wagtail.core.fields import StreamField
from wagtail.core.models import Page, Orderable
from wagtail.images.edit_handlers import ImageChooserPanel
from wagtail.images.api.fields import ImageRenditionField
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
from wagtail.snippets.models import register_snippet

@@ -66,7 +67,17 @@ def author_image(self):
api_fields = [
APIField("author_name"),
APIField("author_website"),
# This is using a custom django rest framework serializer
APIField("author_image", serializer=ImageSerializedField()),
# The below APIField is using a Wagtail-built DRF Serializer that supports
# custom image rendition sizes
APIField(
"image",
serializer=ImageRenditionField(
'fill-200x250',
source="author_image"
)
),
]


1 comment on commit ec1b75b

@KalobTaulien

This comment has been minimized.

Copy link
Member Author

KalobTaulien commented on ec1b75b Apr 1, 2019

Please sign in to comment.
You can’t perform that action at this time.