How to properly save a ManyToManyField in DRF #8473
Unanswered
dsaltyfrere
asked this question in
Question & Answer
Replies: 1 comment
-
Same problem... Have you found a solution? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a
published_item
model which has assignablecategories
. For some reason I'm only able to save one of the categories but I believe i'm doing something wrong.My PublishedItemViewSet looks as follows
The PublishedItemSerializer is
My PublishedItem model:
My Category model:
If I check the incoming
validated_data
I have the following<QueryDict: {'csrfmiddlewaretoken': ['PYA5owmCTSsuuqqTG2D0OySwalZD0D88PZT7Ft0NqwxPnsAhmTUdH1dV1e0SXiyz'], 'url': ['https://www.reuters.com/search/news?sortBy=date&dateRange=all&blob=cryptocurrencies'], 'category': ['elliptic', 'another category', 'third category'], 'text': ['test'], 'photo': [''], 'updated_at': ['']}>
So I should be able to do
However, the incoming validated_data["category"] is a string and not a list, when I attempt to iterate over this object i'm receiving single chars rather than the full category name.
What am I doing wrong, how do I properly save ManyToMany relations in DRF?
Beta Was this translation helpful? Give feedback.
All reactions