I am currently doing a project which requires pagination. A list of Images is provided to the user and whether they were Favorited or not by user.
Favorited Images are kept in a separate table.
In order to provide a list of images and ones that were Favorited by the user an annotate.
def _get_queryset(self, request):
user_favorited = DjImagingImagefavorites.objects.filter(ifv_img_recordid__exact=OuterRef('pk'), ifv_user_id__exact=request.user.profile)
queryset = DjImagingImage.objects.all().annotate(favorited=Exists(user_favorited))
return queryset
Then in the list function
def list(self, request):
images = self._get_queryset(request)
page = self.paginate_queryset(images) #Breaks here
The Query then throws an error. ]Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.
Due to an oddities of how the paginate function performs the count and constructs an illegal sql statement.
Question is - Is their a better way about going to do this or should this work perfectly as I thought it should have?