Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Error checking for nested writes #4682

Closed
@kaseyb002

Description

@kaseyb002

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp