3👍
I believe you need to create an ‘update’ method on your job serializer. See the documentation here: http://www.django-rest-framework.org/api-guide/relations/#writable-nested-serializers. By default a serializer doesn’t understand how to save a nested serializer.
Your update method might look like this:
def update(self, instance, validated_data, id):
# Perform any updates to the instance you want to do
# using the validated_data, then save the category
instance.category = modelJobCategory.objects.get_or_create(
name=validated_data['category']['name']
)
A simpler, perhaps nicer approach would be to use a writable SlugRelatedField. So changing your update job serializer to have a category field that looks like:
category = SlugRelatedField(slug_field='name')
This way when you are saving the job with it’s category you just send the name of the category. Not the whole category object.
If you want to understand what the error means. Django rest framework is trying to figure out which category to save on your job. But to do that it would use a primary key. The database id. An integer. What you’re sending in your PUT request is the category dict, with name and description. But no database id. And django has no idea how to turn that dictionary object into a category that it can save to the database for you.