Skip to content
Advertisement

Django/Wagtail Snippet Serializer in API

I have added wagtail CMS’s blog author in my ‘models.py’ also exposed it in API, but it’s showing like this in API

JavaScript

Here’s the models.py code

JavaScript

How do I serialize like this show author name, website, image and id?

I tried to Serialize the BlogAuthor

JavaScript

And here is the API field

APIField("blog_authors", serializer=AuthorSerializer(many=True)),

When I runserver I got this error

JavaScript

How I can perfectly serialize my blog author?

Advertisement

Answer

I think the problem is there is an intermediate model between your Blog and BlogAuthor – the BlogAuthorsOrderable that has the sort_order field. I don’t know how to get exactly what you are asking for but try changing your AuthorSerializer as follows. Hopefully that will give you enough information to figure out your next steps.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement