def filter_count_predicate(self, qs: QuerySet) -> CustomCountQuerySet: inner_query = stringify_queryset(qs) qs = CustomCountQuerySet.wrap(qs) # type: CustomCountQuerySet full_query = f'SELECT COUNT(text_unit_id) FROM ({inner_query} LIMIT {self.LIMIT_QUERY}) AS temp;' qs.set_optional_count_query(full_query) return qs