filtering queryset in CreateAPIView view

18 views
Skip to first unread message

Larry Martell

unread,
Dec 28, 2022, 11:32:25 AM12/28/22
to django...@googlegroups.com
I have a CreateAPIView view with this code in the serializer:

class AssignWorkItemSerializer(serializers.Serializer, WorkitemSerializerMixin):
assigneeIds = serializers.ListSerializer(
child=serializers.PrimaryKeyRelatedField(
queryset=get_user_model().objects.filter(userrole__role__name='analyst')
),
source='assignees'
)

This is failing because that query returns multiple rows. I want to
filter that queryset at run time by something that is available to me
in the request. Is there a way to do that?
Reply all
Reply to author
Forward
0 new messages