Skip to content

Commit

Permalink
Update DjangoModelFormMutation to honor input_field_name
Browse files Browse the repository at this point in the history
  • Loading branch information
eprikazc committed May 18, 2021
1 parent 623d0f2 commit c73ce86
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions graphene_django/forms/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ def perform_mutate(cls, form, info):
class DjangoModelDjangoFormMutationOptions(DjangoFormMutationOptions):
model = None
return_field_name = None
input_field_name = None


class DjangoModelFormMutation(BaseDjangoFormMutation):
_DEFAULT_INPUT_FIELD_NAME = "input"

class Meta:
abstract = True

Expand All @@ -127,6 +130,7 @@ def __init_subclass_with_meta__(
return_field_name=None,
only_fields=(),
exclude_fields=(),
input_field_name=_DEFAULT_INPUT_FIELD_NAME,
**options
):

Expand Down Expand Up @@ -166,6 +170,17 @@ def __init_subclass_with_meta__(
super(DjangoModelFormMutation, cls).__init_subclass_with_meta__(
_meta=_meta, input_fields=input_fields, **options
)
cls.input_field_name = input_field_name
if cls.input_field_name != cls._DEFAULT_INPUT_FIELD_NAME:
cls._meta.arguments[cls.input_field_name] = cls._meta.arguments.pop(
cls._DEFAULT_INPUT_FIELD_NAME
)

@classmethod
def mutate(cls, root, info, **kwargs):
if cls.input_field_name != cls._DEFAULT_INPUT_FIELD_NAME:
kwargs[cls._DEFAULT_INPUT_FIELD_NAME] = kwargs.pop(cls.input_field_name)
return super(DjangoModelFormMutation, cls).mutate(root, info, **kwargs)

@classmethod
def mutate_and_get_payload(cls, root, info, **input):
Expand Down

0 comments on commit c73ce86

Please sign in to comment.