The Python Oracle

How to use PrimaryKeyRelatedField to update categories on a many-to-many relationship

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: A Thousand Exotic Places Looping v001

--

Chapters
00:00 How To Use Primarykeyrelatedfield To Update Categories On A Many-To-Many Relationship
01:09 Accepted Answer Score 6
01:27 Thank you

--

Full question
https://stackoverflow.com/questions/3080...

--

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.