@@ -19,3 +19,50 @@ You can create a Mutation based on a serializer by using the
1919 class Meta :
2020 serializer_class = MySerializer
2121
22+ Create/Update Operations
23+ ---------------------
24+
25+ By default ModelSerializers accept create and update operations. To
26+ customize this use the `model_operations ` attribute. The update
27+ operation looks up models by the primary key by default. You can
28+ customize the look up with the lookup attribute.
29+
30+ Other default attributes:
31+
32+ `partial = False `: Accept updates without all the input fields.
33+
34+ .. code :: python
35+
36+ from graphene_django.rest_framework.mutation import SerializerMutation
37+
38+ class AwesomeModelMutation (SerializerMutation ):
39+ class Meta :
40+ serializer_class = MyModelSerializer
41+ model_operations = [' create' , ' update' ]
42+ lookup_field = ' id'
43+
44+ Overriding Update Queries
45+ -------------------------
46+
47+ Use the method `get_serializer_kwargs ` to override how
48+ updates are applied.
49+
50+ .. code :: python
51+
52+ from graphene_django.rest_framework.mutation import SerializerMutation
53+
54+ class AwesomeModelMutation (SerializerMutation ):
55+ class Meta :
56+ serializer_class = MyModelSerializer
57+
58+ @ classmethod
59+ def get_serializer_kwargs (cls , root , info , ** input ):
60+ if ' id' in input :
61+ instance = Post.objects.filter(id = input [' id' ], owner = info.context.user).first()
62+ if instance:
63+ return {' instance' : instance, ' data' : input , ' partial' : True }
64+
65+ else :
66+ raise http.Http404
67+
68+ return {' data' : input , ' partial' : True }
0 commit comments