Skip to content

Commit ec1b75b

Browse files
committed
Serializing Images with Wagtails ImageRenditionField
1 parent 2c52d07 commit ec1b75b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

blog/models.py

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from wagtail.core.fields import StreamField
2020
from wagtail.core.models import Page, Orderable
2121
from wagtail.images.edit_handlers import ImageChooserPanel
22+
from wagtail.images.api.fields import ImageRenditionField
2223
from wagtail.contrib.routable_page.models import RoutablePageMixin, route
2324
from wagtail.snippets.models import register_snippet
2425

@@ -66,7 +67,17 @@ def author_image(self):
6667
api_fields = [
6768
APIField("author_name"),
6869
APIField("author_website"),
70+
# This is using a custom django rest framework serializer
6971
APIField("author_image", serializer=ImageSerializedField()),
72+
# The below APIField is using a Wagtail-built DRF Serializer that supports
73+
# custom image rendition sizes
74+
APIField(
75+
"image",
76+
serializer=ImageRenditionField(
77+
'fill-200x250',
78+
source="author_image"
79+
)
80+
),
7081
]
7182

7283

0 commit comments

Comments
 (0)