AltSchool / dynamic-rest

Dynamic extensions for Django REST Framework
MIT License
831 stars 109 forks source link

How to override create method in DynamicModelSerializer so that an object of the nested serializer can be created #314

Open xtrm-co-in opened 3 years ago

xtrm-co-in commented 3 years ago

I have a Transaction model having OneToMany (Foreignkey) relation with Details model. i.e. One transaction can have multiple details. I have nested Details serializer within Transaction serializer which works fine for listing and retrieving. However, I want to override create method in Transaction serializer in such a way that I can create an instance of Details object from the list provided in the request body while simultaneously creating an instance of the Transaction Object. Create method that I have overridden in drf's ModelSerializer works just fine but same isn't working with DynamicModelSerializer. Can you please guide me on how to do it ?