Skip to content

Commit

Permalink
Fixed #33 -- Fixed total no. of rows when view is using multiple filt…
Browse files Browse the repository at this point in the history
…er back-ends.
  • Loading branch information
felixxm committed Feb 20, 2019
1 parent ca01761 commit 4db3d6b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rest_framework_datatables/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def filter_queryset(self, request, queryset, view):
if request.accepted_renderer.format != 'datatables':
return queryset

total_count = queryset.count()
filtered_count_before = queryset.count()
total_count = view.get_queryset().count()
# set the queryset count as an attribute of the view for later
# TODO: find a better way than this hack
setattr(view, '_datatables_total_count', total_count)
Expand Down Expand Up @@ -66,7 +67,7 @@ def filter_queryset(self, request, queryset, view):
queryset = queryset.filter(q).distinct()
filtered_count = queryset.count()
else:
filtered_count = total_count
filtered_count = filtered_count_before
# set the queryset count as an attribute of the view for later
# TODO: maybe find a better way than this hack ?
setattr(view, '_datatables_filtered_count', filtered_count)
Expand Down

0 comments on commit 4db3d6b

Please sign in to comment.