Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flyly0755 opened this issue Jul 14, 2022 · 0 comments
Open

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

flyly0755 opened this issue Jul 14, 2022 · 0 comments

Comments

@flyly0755
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant