Enable cursor pagination of value querysets. by kmwenja · Pull Request #4569 · encode/django-rest-framework (original) (raw)
To do GROUP_BY
queries in django requires one to use .values()
eg this groups posts by user getting a count of posts per user.
Posts.objects.order_by('user').values('user').annotate(post_count=Count('post'))
This would produce a value queryset which serializes its result
objects as dictionaries while CursorPagination
requires a queryset
with result objects that are model instances.
This commit enables cursor pagination for value querysets.
- had to mangle the tests a bit to test it out. They might need
some refactoring. - tried the same for
.values_list()
but it turned out to be
trickier than I expected since you have to use tuple indexes.