I'm retrieving a list of pages via a custom API endpoint called sitemap
. The goal of this endpoint is to return just the URL and last_updated flag so that I can generate a sitemap.xml file for my website. I can't apply a custom serializer to the model as I don't want to affect the normal pages API endpoint we're using.
Is it possible to apply a serializer to an API queryset rather than serializing it at the model level?
I could probably do this with a list comprehension, but a custom serializer feels like a better solution.
So it turns out that it's much easier than I thought. I created a custom serializer:
Then applied that serializer to my APIEndpoint class:
I think the thing that threw me off was that the property wasn't called
serializer_class
.