📜  动态限制相关字段的查询集 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:26.029000             🧑  作者: Mango

代码示例5
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