Answers for "why do i just get <QuerySet []> in django"

7

objects.filter django

>>> Entry.objects.filter(blog_id=4)
Posted by: Guest on September-03-2020
0

get queryset

class PurchaseList(generics.ListAPIView):
    serializer_class = PurchaseSerializer

    def get_queryset(self):
        """
        Optionally restricts the returned purchases to a given user,
        by filtering against a `username` query parameter in the URL.
        """
        queryset = Purchase.objects.all()
        username = self.request.query_params.get('username', None)
        if username is not None:
            queryset = queryset.filter(purchaser__username=username)
        return queryset
Posted by: Guest on July-31-2020

Python Answers by Framework

Browse Popular Code Answers by Language