You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This fixes what appear to be some code errors/typos:
* The `FormMutation` class was renamed to `DjangoFormMutation`, and `ModelFormMutation` to `DjangoModelFormMutation`, in 40610c6.
* `form_valid` was renamed to `perform_mutate` in 463ce68.
It also clarifies a few things that I found confusing:
* It explicitly mentions that `perform_mutate` is a class method.
* The code samples now import the form classes from their packages, so readers know where to import them from too.
Copy file name to clipboardExpand all lines: docs/form-mutations.rst
+12-8Lines changed: 12 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,27 +4,31 @@ Integration with Django forms
4
4
Graphene-Django comes with mutation classes that will convert the fields on Django forms into inputs on a mutation.
5
5
*Note: the API is experimental and will likely change in the future.*
6
6
7
-
FormMutation
8
-
------------
7
+
DjangoFormMutation
8
+
------------------
9
9
10
10
.. code:: python
11
11
12
+
from graphene_django.forms.mutation import DjangoFormMutation
13
+
12
14
classMyForm(forms.Form):
13
15
name = forms.CharField()
14
16
15
-
classMyMutation(FormMutation):
17
+
classMyMutation(DjangoFormMutation):
16
18
classMeta:
17
19
form_class = MyForm
18
20
19
21
``MyMutation`` will automatically receive an ``input`` argument. This argument should be a ``dict`` where the key is ``name`` and the value is a string.
20
22
21
-
ModelFormMutation
22
-
-----------------
23
+
DjangoModelFormMutation
24
+
-----------------------
23
25
24
-
``ModelFormMutation`` will pull the fields from a ``ModelForm``.
26
+
``DjangoModelFormMutation`` will pull the fields from a ``ModelForm``.
25
27
26
28
.. code:: python
27
29
30
+
from graphene_django.forms.mutation import DjangoModelFormMutation
31
+
28
32
classPet(models.Model):
29
33
name = models.CharField()
30
34
@@ -61,8 +65,8 @@ Form validation
61
65
62
66
Form mutations will call ``is_valid()`` on your forms.
63
67
64
-
If the form is valid then ``form_valid(form, info)`` is called on the mutation. Override this method to change how
65
-
the form is saved or to return a different Graphene object type.
68
+
If the form is valid then the class method ``perform_mutate(form, info)`` is called on the mutation. Override this method
69
+
to change how the form is saved or to return a different Graphene object type.
66
70
67
71
If the form is *not* valid then a list of errors will be returned. These errors have two fields: ``field``, a string
68
72
containing the name of the invalid form field, and ``messages``, a list of strings with the validation messages.
0 commit comments