How to programmatically provide `queryset` to PrimaryKeyRelatedField in DRF 3

后端 未结 2 1840
无人及你
无人及你 2021-02-02 15:14

In order to have a non-readonly PrimaryKeyRelatedField, you are required to provide a queryset that contains valid options.

How can I properly populate that

2条回答
  •  鱼传尺愫
    2021-02-02 16:12

    View has a

    self.request.user
    

    attribute which you can then use to fetch user related queryset eg

    queryset = Products.objects.get(customer=self.request.user)
    

提交回复
热议问题