New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: serializer_class
instead of api_fields
#2148
Comments
Hi @e-kondr01! Just to clarify, Pipit does not use the Wagtail API, instead we use a system where we, using a custom API, locates pages using their path and transforms them to data using serializers. With this in mind, to your question, there are no considerations since we do not use the API. In fact We originally started with using |
Understood. I see why you would want to use a whole serializer class instead of serializers for fields only. Are there any utilities that may be missing when using Pipit for API, compared to Wagtail API V2? For instance, I see wagtail api has additional serializer field classes apart from |
@e-kondr01 The Wagtail API sort of builds up a dynamic serializer based on the Page structure and api_fields, in this process certain fields are automatically mapped, this magic is lost in Pipit as we have a more explicit approach of defining serializers. But other then that, everything else should work, the Wagtail API is built on rest framework and serializers. This is sort of how the Wagtail auto mapping works, if you want to play with it. from wagtail.api.v2.serializers import get_serializer_class, PageSerializer
# self here is the page
fields = [f.name for f in self.api_fields]
child_serializers = {
f.name: f.serializer
for f in self.api_fields
if f.serializer
}
serializer_class = get_serializer_class(
type(self),
fields,
[PagesAPIViewSet.meta_fields],
child_serializer_classes=child_serializers,
base=PageSerializer
)
serializer = serializer_class(self)
data = serializer.data |
Got it, thanks for clarifying. This info may be useful for other people discovering |
To expose
Page
fields over API and specify their serialization, Wagtail API v2 uses Page's attributeapi_fields
.Wagtail-Pipit
docs say that you use Page's attributeserializer_class
for this. What were the considerations when changing it from the default wagtail api's implementation?The text was updated successfully, but these errors were encountered: