1users = UserClasses.objects.filter(class_id=data['class_id'])
2user_details = User.objects.filter(id__in=users.values_list('id', flat=True))
1class PurchaseList(generics.ListAPIView):
2 serializer_class = PurchaseSerializer
3
4 def get_queryset(self):
5 """
6 Optionally restricts the returned purchases to a given user,
7 by filtering against a `username` query parameter in the URL.
8 """
9 queryset = Purchase.objects.all()
10 username = self.request.query_params.get('username', None)
11 if username is not None:
12 queryset = queryset.filter(purchaser__username=username)
13 return queryset
1from myapp.models import Purchase
2from myapp.serializers import PurchaseSerializer
3from rest_framework import generics
4
5class PurchaseList(generics.ListAPIView):
6 serializer_class = PurchaseSerializer
7
8 def get_queryset(self):
9 """
10 This view should return a list of all the purchases
11 for the currently authenticated user.
12 """
13 user = self.request.user
14 return Purchase.objects.filter(purchaser=user)