Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to handle included resources during creation#1014

Unanswered
jokiefer asked this question inQ&A
Discussion options

Short scenario

Like discussed injsonapi forum i would like to create included resources on create.

Given there are the following serializers:

fromrest_framework.serializersimportHyperlinkedIdentityFieldfromregistry.modelsimportMapContext,MapContextLayerfromrest_framework_json_api.serializersimportModelSerializerfromrest_framework_json_api.relationsimportHyperlinkedRelatedFieldclassMapContextLayerSerializer(ModelSerializer):url=HyperlinkedIdentityField(view_name='registry:mapcontextlayer-detail',    )classMeta:model=MapContextLayerfields="__all__"classMapContextSerializer(ModelSerializer):url=HyperlinkedIdentityField(view_name='registry:mapcontext-detail',    )included_serializers= {'map_context_layers':MapContextLayerSerializer,    }classMeta:model=MapContextfields="__all__"

Given there are following views

fromrest_framework_json_api.schemas.openapiimportAutoSchemafromrest_framework_extensions.mixinsimportNestedViewSetMixinfromrest_framework_json_api.viewsimportModelViewSet,RelationshipViewfromregistry.api.serializers.mapcontextimportMapContextSerializer,MapContextLayerSerializerfromregistry.modelsimportMapContext,MapContextLayerclassMapContextRelationshipView(RelationshipView):schema=AutoSchema(tags=['MapContext'],    )queryset=MapContext.objectsclassMapContextViewSet(NestedViewSetMixin,ModelViewSet):schema=AutoSchema(tags=['MapContext'],    )queryset=MapContext.objects.all()serializer_class=MapContextSerializerprefetch_for_includes= {'__all__': [],'map_context_layers': ['map_context_layers']    }classMapContextLayerViewSet(ModelViewSet):schema=AutoSchema(tags=['MapContext'],    )queryset=MapContextLayer.objects.all()serializer_class=MapContextLayerSerializerdefget_queryset(self):queryset=super(MapContextLayerViewSet,self).get_queryset()if'map_context_pk'inself.kwargs:map_context_pk=self.kwargs['map_context_pk']queryset=queryset.filter(map_context__pk=map_context_pk)returnqueryset

Given i would post the following json with client generated uuid's

{"data": {"type":"MapContext","id":"3a003511-5e46-4102-b63f-65ea73fff51e","attributes": {"title":"nice mapcontext","abstract":"short abstract"    },"relationships": {"map_context_layers": {"data": [          {"type":"MapContextLayer","id":"f8c0c58b-1853-4bf3-9bc1-5a467ce8b153"},          {"type":"MapContextLayer","id":"dd319bf6-9a3b-45d7-883f-eccffac5c76b"}        ]      },"owned_by_org": {"data": {"type":"Organization","id":"b2fdc463-87cb-4deb-b39b-187f7616d1df"}      }    }  },"included": [{"type":"MapContextLayer","id":"f8c0c58b-1853-4bf3-9bc1-5a467ce8b153","attributes": {"name":"0","title":"nice title"    },"relationships": {"map_context": {"data": {"type":"MapContext","id":"3a003511-5e46-4102-b63f-65ea73fff51e"}      }    }  },{"type":"MapContextLayer","id":"dd319bf6-9a3b-45d7-883f-eccffac5c76b","attributes": {"name":"0.1","title":"nice title"    },"relationships": {"parent": {"data": {"type":"MapContextLayer","id":"f8c0c58b-1853-4bf3-9bc1-5a467ce8b153"}      },"map_context": {"data": {"type":"MapContext","id":"3a003511-5e46-4102-b63f-65ea73fff51e"}      }    }  }]}

Question

For now i can post on the mapcontext creat endpoint to create aMapContext resource, but the included resource objects are not handled for now. Only theMapContext object is stored in the database.

Does DJA support saving of POSTed included resource objects?

You must be logged in to vote

Replies: 1 comment

Comment options

Maybe my Problem is solvable by using thediscussed atomic feature.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@jokiefer

[8]ページ先頭

©2009-2025 Movatter.jp