Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

dynamically created queryset for PrimaryKeyRelatedField in drf

class UserFilteredPrimaryKeyRelatedField(serializers.PrimaryKeyRelatedField):
    def get_queryset(self):
        request = self.context.get('request', None)
        queryset = super(UserFilteredPrimaryKeyRelatedField, self).get_queryset()
        if not request or not queryset:
            return None
        return queryset.filter(user=request.user)
      

class MySerializer(serializers.ModelSerializer):
    related = UserFilteredPrimaryKeyRelatedField(queryset=MyModel.objects)
Comment

PREVIOUS NEXT
Code Example
Python :: django listview 
Python :: logistic distribution location and scale parameters 
Python :: python project 
Python :: Python - Cómo comprobar si dos cuerdas son anagramas 
Python :: text files to words generator 
Python :: Django Signup urls.py 
Python :: how to import autpy 
Python :: bouon arrondi tkinter 
Python :: sorting-a-python-list-by-two-fields 
Python :: display all rows pandas 
Python :: countvectorizer minimum frequency 
Python :: django auto complete light styling 
Python :: mu python replicate array n times 
Python :: spark group by alias 
Python :: compare if 2 numbers are relatively equal 
Python :: python .exe long start 
Python :: python wait for executable to finish before perceeding 
Python :: pil 
Python :: argmax change dafault value for multiple maxima 
Python :: django app directory 
Python :: convert an image to matrix in python 
Python :: how to take multiple integer input in python 
Python :: Maximum number of guests on cruise at an instance tcs 
Python :: python read file to eof 
Python :: keep only min entries in dataframe grouped by one column 
Python :: stop animation matplotlib 
Python :: pandas 3d set camara cords 
Python :: how to print a text 
Python :: .lowertkinter 
Python :: how to convert ui file to py file 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =