Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Dynamically limiting queryset of related field

class PurchaseSerializer(serializers.HyperlinkedModelSerializer):
    def get_fields(self, *args, **kwargs):
        fields = super(PurchaseSerializer, self).get_fields(*args, **kwargs)
        fields['purchaser'].queryset = permitted_objects(self.context['view'].request.user, fields['purchaser'].queryset)
        return fields

    class Meta:
        model = Purchase
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Dynamically #limiting #queryset #related #field
ADD COMMENT
Topic
Name
1+3 =