How to use PrimaryKeyRelatedField to update categories on a many-to-many relationship
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Question
01:28 Accepted answer (Score 4)
01:53 Thank you
--
Full question
https://stackoverflow.com/questions/3080...
Question links:
[PrimaryKeyRelatedField]: http://www.django-rest-framework.org/api...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #djangorestframework
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game Looping
--
Chapters
00:00 Question
01:28 Accepted answer (Score 4)
01:53 Thank you
--
Full question
https://stackoverflow.com/questions/3080...
Question links:
[PrimaryKeyRelatedField]: http://www.django-rest-framework.org/api...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #djangorestframework
#avk47
ACCEPTED ANSWER
Score 6
For anyone else having this issue I found a solution that allows PrimaryKeyRelatedField to be read/writeable. Just add queryset
categories = serializers.PrimaryKeyRelatedField(many=True, queryset=Category.objects.all())
It will still filter on the correct relationship which is a bit confusing.