Yura Khkyan
Yura Khkyan

Reputation: 111

Wagtail filter by related model field in PagesAPIViewSet

I have EntryPage model that have M2M relation to Category (categories field name).

I've added viewset for Entries:

class EntriesViewSet(PagesAPIViewSet):
    base_serializer_class = EntryPageWithSiblingsSerializer
    model = EntryPage
    body_fields = PagesAPIViewSet.body_fields + EntryPageWithSiblingsSerializer.Meta.fields
    listing_default_fields = PagesAPIViewSet.listing_default_fields + EntryPageWithSiblingsSerializer.Meta.fields
    detail_only_fields = ["prev_entry", "next_entry"]

Now I want to be able to filter entries by Category's name. Like following: /wt/api/nextjs/v1/blog_entries/?categories__name=name. Is there easy way to do that using existing FilerBackends, or I need to write my own?

Upvotes: 2

Views: 100

Answers (0)

Related Questions