wagtail / wagtail

A Django content management system focused on flexibility and user experience

Home Page:https://wagtail.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot specify `order` for admin API page results when using `for_explorer`

maya413 opened this issue · comments

when i get sidebar pages use below url :
api/main/pages/?child_of=4&for_explorer=1&fields=parent&order=-id
response is : filtering by for_explorer without child_of is not supported

but when i get sidebar pages use below url :
api/main/pages/?child_of=4&for_explorer=1&fields=parent
response is fine,

Thanks for the report @maya413! I can confirm I'm seeing the same issue when testing against bakerydemo:

http://localhost:8000/admin/api/main/pages/?child_of=1&for_explorer=1&fields=parent returns results
http://localhost:8000/admin/api/main/pages/?child_of=1&for_explorer=1&fields=parent&order=id returns the error filtering by for_explorer without child_of is not supported

It looks like this is because the for_explorer filter relies on a _filtered_by_child_of attribute being set on the queryset, but applying an ordering replaces that queryset with a new one.

The admin API isn't really intended to be used outside of Wagtail's own code, but I'll accept this as a legitimate bug.