class PhoneSerializer(DynamicFieldsMixin, NestedModelSerializer):
phone_type = NestedField(PhoneTypeSerializer)
class Meta:
model = Phone
fields = '__all__'
class PhoneTypeSerializer(DynamicFieldsMixin, serializers.ModelSerializer):
class Meta:
model = PhoneType
fields = '__all__'
It fails when it reaches the phone_type field.
Is it because I'm trying to create the PhoneType object in the create operation which is supposed to create Phone?
Full traceback:
Traceback (most recent call last):
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\generics.py", line 242, in post
return self.create(request, *args, **kwargs)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\mixins.py", line 19, in create
self.perform_create(serializer)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\mixins.py", line 24, in perform_create
serializer.save()
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\serializers.py", line 205, in save
self.instance = self.create(validated_data)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django_restql\mixins.py", line 702, in create
fields["foreignkey_related"]["writable"]
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django_restql\mixins.py", line 585, in create_writable_foreignkey_related
obj = serializer.save()
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\serializers.py", line 205, in save
self.instance = self.create(validated_data)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django_restql\mixins.py", line 710, in create
fields["many_to"]["many_related"]
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django_restql\mixins.py", line 649, in create_many_to_many_related
pks = self.bulk_create_objs(field, values[operation])
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django_restql\mixins.py", line 605, in bulk_create_objs
obj = serializer.save()
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\rest_framework\serializers.py", line 205, in save
self.instance = self.create(validated_data)
File "fasdfdsafdasfsda\backend\.venv\lib\site-packages\django_restql\mixins.py", line 678, in create
if field_serializer.is_replaceable:
AttributeError: 'NestedSerializer' object has no attribute 'is_replaceable'
[21/Jan/2021 21:57:09] "POST /api/companies/ HTTP/1.1" 500 25677
I'm getting the above error when I try to create nested objects.
My serializers:
This is the request:
It fails when it reaches the phone_type field. Is it because I'm trying to create the
PhoneType
object in thecreate
operation which is supposed to createPhone
?Full traceback: