[Answered ]-Overwrite update and to_representation method throws AttributeError at POST request

1👍

From DRF docs

If you want to implement a read-write relational field, you must also
implement the .to_internal_value(self, data) method.

So, you want to implement a read-write(POST/GET) field, so you need to implement .to_internal_value method in your serializer.

👤levi

1👍

You need to use nested serializers. The error is saying that there is no firstname filed on employee, which there isn’t. You need a serializer for both the Employee and UserData.

0👍

I recently faced the same issue where I overwrote the to_representation and create method for the serializer.

In my case I forgot to add serializer.save() in my viewset. The issue got resolved after adding it.

The cause of the error was when I called the serializer in the viewset it passed the body of the POST request as OrderedDict to the obj in to_representation method.

Leave a comment