Skip to content

Fix code errors in form-mutations.rst #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docs/form-mutations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,31 @@ Integration with Django forms
Graphene-Django comes with mutation classes that will convert the fields on Django forms into inputs on a mutation.
*Note: the API is experimental and will likely change in the future.*

FormMutation
------------
DjangoFormMutation
------------------

.. code:: python

from graphene_django.forms.mutation import DjangoFormMutation

class MyForm(forms.Form):
name = forms.CharField()

class MyMutation(FormMutation):
class MyMutation(DjangoFormMutation):
class Meta:
form_class = MyForm

``MyMutation`` will automatically receive an ``input`` argument. This argument should be a ``dict`` where the key is ``name`` and the value is a string.

ModelFormMutation
-----------------
DjangoModelFormMutation
-----------------------

``ModelFormMutation`` will pull the fields from a ``ModelForm``.
``DjangoModelFormMutation`` will pull the fields from a ``ModelForm``.

.. code:: python

from graphene_django.forms.mutation import DjangoModelFormMutation

class Pet(models.Model):
name = models.CharField()

Expand Down Expand Up @@ -61,8 +65,8 @@ Form validation

Form mutations will call ``is_valid()`` on your forms.

If the form is valid then ``form_valid(form, info)`` is called on the mutation. Override this method to change how
the form is saved or to return a different Graphene object type.
If the form is valid then the class method ``perform_mutate(form, info)`` is called on the mutation. Override this method
to change how the form is saved or to return a different Graphene object type.

If the form is *not* valid then a list of errors will be returned. These errors have two fields: ``field``, a string
containing the name of the invalid form field, and ``messages``, a list of strings with the validation messages.