Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

get queryset

from myapp.models import Purchase
from myapp.serializers import PurchaseSerializer
from rest_framework import generics

class PurchaseList(generics.ListAPIView):
    serializer_class = PurchaseSerializer

    def get_queryset(self):
        """
        This view should return a list of all the purchases
        for the currently authenticated user.
        """
        user = self.request.user
        return Purchase.objects.filter(purchaser=user)
Comment

PREVIOUS NEXT
Code Example
Python :: how to close turle loop 
Python :: combine all lines with same value of a column unix 
Python :: python matrix condensed to square 
Python :: ec2 ssh terminal hangs after sometime 
Python :: can only concatenate str (not "numpy.uint8") to str 
Python :: rename a variable using .format in python 
Python :: gdal user with anaconda 
Python :: roganrola 
Python :: flask google analytics 
Python :: python if dataframe has at least one row 
Python :: inspect last 5 rows of dataframe 
Python :: how to sort variable in specifiic order in python 
Python :: fibonacci numbers function python print 
Python :: repeats in python 
Python :: indentation error in python atom editor 
Python :: Count total number of null, isna sum python 
Python :: updating to database 
Python :: json timestamp to date python 
Python :: python split files into even sets of folders 
Python :: mechanize python LE #3 
Python :: comment interpreter tuple python avec valeur unique 
Python :: how to insert ele in python 
Python :: diccionario 
Python :: How to avoit print() to go to newline each time 
Python :: Doubleclick .py Prep Mac 
Python :: FizzBuzz in Python Using Conditional Statements 
Python :: how parse date python no specific format 
Python :: Using Python Permutations function on a String with extra parameter 
Python :: ascii julius caesar python encryption 
Python :: python how to do imports 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =