Skip to content

how to use with self related field(manytomany) #168

Description

@flyly0755

I have one model with a field which is self related,

class zi(models.Model):
   """汉字数据模型"""
    chszi = models.CharField(max_length=1, null=False, blank=False, verbose_name="汉字", unique=True)
    relatedzi = models.ManyToManyField("self", null=True, blank=True, related_name="rzi",
                                       symmetrical=True, verbose_name='关联字')

class RelatedZiSerializer(serializers.ModelSerializer):
    """关联汉字的序列化"""
    class Meta:
        model = zi
        fields = ['id', 'chszi']


class ziDetialSerializer(WritableNestedModelSerializer, serializers.ModelSerializer):
    """汉字详情的序列化"""
    relatedzi = RelatedZiSerializer(many=True) 

with code above, send a put request to update it, but with error showed below:
image

how to solve this problem?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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