Python Django将数据插入到ManyToManyfield AssertionError错误
模型 看法 序列化程序 类注册序列化程序(DynamicFieldsMixin、DynamicFieldsModelSerializer): dependents=DependentSerializer(many=True,required=False) 错误:Python Django将数据插入到ManyToManyfield AssertionError错误,python,django,Python,Django,模型 看法 序列化程序 类注册序列化程序(DynamicFieldsMixin、DynamicFieldsModelSerializer): dependents=DependentSerializer(many=True,required=False) 错误: class Meta: model = models.Enrollee fields = '__all__' 在这里,我试图为我的家属发送嵌套数据(ManyToManyField) 但是,在插入数据时出现上述错误 我们
class Meta:
model = models.Enrollee
fields = '__all__'
在这里,我试图为我的家属发送嵌套数据(ManyToManyField)
但是,在插入数据时出现上述错误
我们有没有办法做到这一点
_nested_writes
assert not any(
AssertionError: The `.create()` method does not support writable nested fields by default.
Write an explicit `.create()` method for serializer `api.serializers.EnrolleeSerializer`, or set `read_only=True` on nested serializer fields.
以上是我使用post方法发送的数据
请看一看使用
class Meta:
model = models.Enrollee
fields = '__all__'
_nested_writes
assert not any(
AssertionError: The `.create()` method does not support writable nested fields by default.
Write an explicit `.create()` method for serializer `api.serializers.EnrolleeSerializer`, or set `read_only=True` on nested serializer fields.
{
"first_name":"soubhagya",
"dependents" : [
{
"first_name":"soubhagya"
}
]
}