L
L
lyntik2020-05-21 14:55:29
Django
lyntik, 2020-05-21 14:55:29

When adding Count, it throws an error: 'int' object is not iterable. JSON output. You need to know the number of objects. How is life??

class ActiveDriverGetPassgersToOut(generics.ListAPIView):
serializer_class = ActiveDriveSerializers

def get_queryset(self):
queryset = ActiveDriver.objects.all()
index = self.request.query_params.get('iddriver', None)
if index is not None:
qs = queryset.filter(idDriver__exact=index)
q = qs.filter(numberPassengers__ToStop__exact=F('Locate'))
queryset = q.count()

return queryset

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2020-05-21
@zenwalker

0. format the code correctly
1. get_queryset must return exactly QuerySet. You are returning Count
1. You most likely want q.count(). Count is an aggregate function used in agregate and annotate which is a little different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question