Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Closed
Description
I believe this issue was partially addressed in#2263, but I ran into this issue again with a many to many field.
classTesty(models.Model):user_list=models.ManyToManyField('auth.User',related_name='just_test',blank=True)
classTestySerializer(serializers.ModelSerializer):user_list=serializers.SlugRelatedField(slug_field='id',many=True,queryset=User.objects.all())user_list_detail=UserSerializer(source='user_list',many=True,read_only=True)classMeta:model=Testyfields= ('id','user_list','user_list_detail',)
AssertionError: The `.create()` method does not support writable nested fields by default.Write an explicit `.create()` method for serializer `timeslots.serializers.TestySerializer`, or set `read_only=True` on nested serializer fields.As shown, I've set the nested serializer field as read_only=True. When I delete the user_list_detail field, everything works fine. My goal is to write into the user_list field using ids, but be able to read the user list fields using UserSerializer (to get the depth).
This problem does not occur with ForeignKey fields. Additionally, reading works fine with the user_list_detail field included, but writes do not work.
Metadata
Metadata
Assignees
Labels
No labels