- Notifications
You must be signed in to change notification settings - Fork302
-
Short scenarioLike 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"} } } }]} QuestionFor now i can post on the mapcontext creat endpoint to create a Does DJA support saving of POSTed included resource objects? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment
-
Maybe my Problem is solvable by using thediscussed atomic feature. |
BetaWas this translation helpful?Give feedback.
All reactions
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment