Coder Social home page Coder Social logo

Comments (4)

gecBurton avatar gecBurton commented on August 13, 2024 3

I am also facing the same issue. @pferreira101 I have a very nasty work around that is good enough for now that you might want

class CommonModel(PolymorphicModel):
    def __init__(self, *args, **kwargs):
        self._save_kwargs = defaultdict(dict)
        super().,__init__(*args, **kwargs)
    ... # etc

i will try and find something more satisfactory soon!

from drf-writable-nested.

csdenboer avatar csdenboer commented on August 13, 2024

I'm having the same issue. Did you manage to solve it?

from drf-writable-nested.

js-moreno avatar js-moreno commented on August 13, 2024

@mattkamp how did you resolve it?, i have same problem. I get same AttributeError in serializer object: object has no attribute '_save_kwargs' when i try to save nested models in a polymorphic specific resource type

from drf-writable-nested.

pferreira101 avatar pferreira101 commented on August 13, 2024

I am facing the same error in an identical situation.

I am using a PolymorphicSerializer that maps 3 model serializers.

class PolySerializer(PolymorphicSerializer):
    model_serializer_mapping = {
        ModelA: ModelASerializer,
        ModelB: ModelBSerializer,
        ModelC: ModelCSerializer,
    }

Then, I have a CommonSerializer that uses the WritableNestedModelSerializer and is extended by all the serializers mapped in the PolymorphicSerializer, such as ModelASerializer.

class CommonSerializer(WritableNestedModelSerializer):
    nested_model = NestedModelSerializer()

    class Meta:
        model = CommonModel
        fields =  [ "field_1", "field_2" ]

class ModelASerializer(CommonSerializer):
    class Meta:
        model = ModelA
        fields = CommonSerializer.Meta.fields + ["field_A"]

Where CommonModel is a PolymorphicModel extended by models A, B and C.

Whenever I try to use the ModelASerializer, I get this error:
AttributeError: 'ModelASerializer' object has no attribute '_save_kwargs'

from drf-writable-nested.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.