peter_evance

Empty Json response list in restframework

Feb 11th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. I have two models Profile and Relationship
  2.  
  3. #Serializer class
  4. class ProfileSerializer(serializers.ModelSerializer):
  5. class Meta:
  6. model = Profile
  7. fields = ['first_name','last_name','bio','email','avatar']
  8.  
  9. #API view class
  10. class ReceivedInvitesList(generics.GenericAPIView,mixins.ListModelMixin):
  11. serializer_class = ProfileSerializer
  12. def get_queryset(self):
  13. profile = Profile.objects.get(user=self.request.user)
  14. queryset = Relationship.objects.invitations_received(profile)
  15. return queryset
  16.  
  17. def get(self, request):
  18. return self.list(request)
  19.  
  20. #Rest framework browser response
  21. HTTP 200 OK
  22. Allow: GET, POST, OPTIONS
  23. Content-Type: application/json
  24. Vary: Accept
  25.  
  26. [
  27. {},
  28. {},
  29. {}
  30. ]
Add Comment
Please, Sign In to add comment