Home > Mobile >  'SearchUsers' object has no attribute 'count'
'SearchUsers' object has no attribute 'count'

Time:08-19

I have problem with this it keeps saying: 'SearchUsers' object has no attribute 'count'

#views

from elasticsearch_dsl import Q

class SearchUsers(PaginatedElasticSearchAPIView):
    serializer_class = UserSerializer
    document_class = UserDocument

    def generate_q_expression(self, query):
        return Q('bool',
                 should=[
                     Q('match', username=query),
                     Q('match', first_name=query),
                     Q('match', last_name=query),
                 ], minimum_should_match=1)

#urls

from django.urls import path
from search.views import SearchUsers

urlpatterns = [
    path('user/<str:query>/', SearchUsers.as_view()),
]

I'm facing this issue for the last 3 days. Searched for the similar question on StackOverflow but nothing helped me. Any Help, Would be appreciated.

Thanks in Advance :)

CodePudding user response:

'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination' 

I forget to add in my settings, which I passed through the class parameter. It solved my issue.

CodePudding user response:

Can you use SearchUsers.objects.count() instead? I can't guarantee that it will work. Can you show me where do you use the count?

And I think count is a function, not an attribute.

  • Related