dev: fix pagination count

This commit is contained in:
pablohashescobar 2024-03-20 17:41:20 +05:30
parent 981ac13812
commit 6ebd215fd6

View File

@ -232,7 +232,9 @@ class GroupedOffsetPaginator(OffsetPaginator):
queryset.values(self.group_by_field_name) queryset.values(self.group_by_field_name)
.annotate( .annotate(
count=Count( count=Count(
self.group_by_field_name, "id",
filter=self.count_filter,
distinct=True,
) )
) )
.order_by("-count")[0]["count"] .order_by("-count")[0]["count"]
@ -247,12 +249,17 @@ class GroupedOffsetPaginator(OffsetPaginator):
) )
def __get_total_queryset(self): def __get_total_queryset(self):
return self.queryset.values(self.group_by_field_name).annotate( return (
self.queryset.values(self.group_by_field_name)
.annotate(
count=Count( count=Count(
self.group_by_field_name, "id",
filter=self.count_filter, filter=self.count_filter,
distinct=True,
) )
) )
.order_by()
)
def __get_total_dict(self): def __get_total_dict(self):
total_group_dict = {} total_group_dict = {}
@ -419,7 +426,9 @@ class SubGroupedOffsetPaginator(OffsetPaginator):
queryset.values(self.group_by_field_name) queryset.values(self.group_by_field_name)
.annotate( .annotate(
count=Count( count=Count(
self.group_by_field_name, "id",
filter=self.count_filter,
distinct=True,
) )
) )
.order_by("-count")[0]["count"] .order_by("-count")[0]["count"]
@ -439,8 +448,9 @@ class SubGroupedOffsetPaginator(OffsetPaginator):
.values(self.group_by_field_name) .values(self.group_by_field_name)
.annotate( .annotate(
count=Count( count=Count(
self.group_by_field_name, "id",
filter=self.count_filter, filter=self.count_filter,
distinct=True,
) )
) )
.distinct() .distinct()
@ -449,8 +459,9 @@ class SubGroupedOffsetPaginator(OffsetPaginator):
def __get_subgroup_total_queryset(self): def __get_subgroup_total_queryset(self):
return self.queryset.values(self.sub_group_by_field_name).annotate( return self.queryset.values(self.sub_group_by_field_name).annotate(
count=Count( count=Count(
self.sub_group_by_field_name, "id",
filter=self.count_filter, filter=self.count_filter,
distinct=True,
) )
) )