Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object of type 'Response' has no len() in DRF

ive combined two models. one model's field is annotated to another model's so they can merge. However, when I try to return the data, I get TypeError: object of type 'Response' has no len(). I've followed several examples on stackoverflow and it doesnt seem to be working.

Here's what I have:

class ExploreAPIView(generics.ListAPIView):

    def get_queryset(self):
        merged_queryset = Place.get_queryset(self.request.user)
        usr_pks = [u.pk for u in merged_queryset]
        queryset = Place.objects.filter(pk__in=usr_pks)

        serialUser = UserSerializer( User.objects.annotate(time=Extract('date_joined','epoch')), many=True).data[:]
        serialPlace = PlacesSerializer(queryset, many=True).data[:]

        chained_list = sorted(serialPlace +serialUser, key=lambda x: x.get('time'))

        return Response(chained_list)

I dont understand why it returns no len() when it returns items if i print out the chained_list

like image 324
hammies Avatar asked Nov 25 '17 19:11

hammies


1 Answers

You're returning a Response from get_queryset. But that method is supposed to return a queryset, as the name implies.

like image 69
Daniel Roseman Avatar answered Nov 07 '22 07:11

Daniel Roseman