-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Can not replace JSONField with a custom Serializer #275
Comments
You should use class ProductSerializer(NestedModelSerializer):
persons = NestedField(PersonSerializer, required=True, many=True)
attributes = NestedField(ProductAttributesSerializer, required=True, many=True) |
Hey @yezyilomo thanks for your answer. I tried your example, but after declaring the field as a AttributeError: type object 'ProductAttributesSerializer' has no attribute 'Meta' Remember that my serializer is trying to replace a JSONField, so it is not associated with any particular model. However for testing purposes I added the meta class like this:
After trying to create a new object I got the following error again: NotImplementedError at /api/v2/product/ Any other ideas? I would appreciate any help! Thanks |
If |
I have the following serializer:
but when I try to change the
attributes
field with a new serializer like this.I get an error when trying to create new objects.
I get the following error:
AssertionError at /api/v2/product/
The
.create()
method does not support writable nested fields by default.Write an explicit
.create()
method for serializer serializers.ProductSerializer, or set
read_only=True` on nested serializer fields.Any ideas on how can I could fix this? Thanks
The text was updated successfully, but these errors were encountered: