Skip to content

Commit c73ce86

Browse files
committed
Update DjangoModelFormMutation to honor input_field_name
Fixes: graphql-python#1037
1 parent 623d0f2 commit c73ce86

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

graphene_django/forms/mutation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ def perform_mutate(cls, form, info):
111111
class DjangoModelDjangoFormMutationOptions(DjangoFormMutationOptions):
112112
model = None
113113
return_field_name = None
114+
input_field_name = None
114115

115116

116117
class DjangoModelFormMutation(BaseDjangoFormMutation):
118+
_DEFAULT_INPUT_FIELD_NAME = "input"
119+
117120
class Meta:
118121
abstract = True
119122

@@ -127,6 +130,7 @@ def __init_subclass_with_meta__(
127130
return_field_name=None,
128131
only_fields=(),
129132
exclude_fields=(),
133+
input_field_name=_DEFAULT_INPUT_FIELD_NAME,
130134
**options
131135
):
132136

@@ -166,6 +170,17 @@ def __init_subclass_with_meta__(
166170
super(DjangoModelFormMutation, cls).__init_subclass_with_meta__(
167171
_meta=_meta, input_fields=input_fields, **options
168172
)
173+
cls.input_field_name = input_field_name
174+
if cls.input_field_name != cls._DEFAULT_INPUT_FIELD_NAME:
175+
cls._meta.arguments[cls.input_field_name] = cls._meta.arguments.pop(
176+
cls._DEFAULT_INPUT_FIELD_NAME
177+
)
178+
179+
@classmethod
180+
def mutate(cls, root, info, **kwargs):
181+
if cls.input_field_name != cls._DEFAULT_INPUT_FIELD_NAME:
182+
kwargs[cls._DEFAULT_INPUT_FIELD_NAME] = kwargs.pop(cls.input_field_name)
183+
return super(DjangoModelFormMutation, cls).mutate(root, info, **kwargs)
169184

170185
@classmethod
171186
def mutate_and_get_payload(cls, root, info, **input):

0 commit comments

Comments
 (0)