I have the following model structure:
class Project(models.Model):
author = models.ManyToManyField(Account)
name = models.CharField(max_length=40, default=\'
There are two problems here:
If the field is used to represent a to-many relationship, you should add the
many=Trueflag to the serializer field.
So you need to add many=True to AccountSerializer:
author = AccountSerializer(read_only=True, required=False, many=True)
By default nested serializers are
read-only. If you want to support write-operations to a nested serializer field you'll need to createcreate()and/orupdate()methods in order to explicitly specify how the child relationships should be saved.
So if you look at the example and the documentation it seems that you need to implement create or update method.