Skip to content
Advertisement

Nested Serializer save post foreign key in django

In my project, the relationship between Product and Group is ManytoOne.

When I tried to post a new product, it cannot work.

I’m sure there are more issues with this code and I will appreciate a detailed answer, because I am new to Django and Python. Thank you in advance.

models.py

JavaScript

serializers.py

JavaScript

views.py

JavaScript

Advertisement

Answer

First change serializers.py:

JavaScript

Then change views.py:

JavaScript
Advertisement