mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-16 19:40:36 +03:00
Fix code errors in form-mutations.rst (#499)
This fixes what appear to be some code errors/typos: * The `FormMutation` class was renamed to `DjangoFormMutation`, and `ModelFormMutation` to `DjangoModelFormMutation`, in40610c64a3
. * `form_valid` was renamed to `perform_mutate` in463ce68b16
. 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.
This commit is contained in:
parent
75bf398523
commit
263c7267cb
|
@ -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.
|
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.*
|
*Note: the API is experimental and will likely change in the future.*
|
||||||
|
|
||||||
FormMutation
|
DjangoFormMutation
|
||||||
------------
|
------------------
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
|
from graphene_django.forms.mutation import DjangoFormMutation
|
||||||
|
|
||||||
class MyForm(forms.Form):
|
class MyForm(forms.Form):
|
||||||
name = forms.CharField()
|
name = forms.CharField()
|
||||||
|
|
||||||
class MyMutation(FormMutation):
|
class MyMutation(DjangoFormMutation):
|
||||||
class Meta:
|
class Meta:
|
||||||
form_class = MyForm
|
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.
|
``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
|
.. code:: python
|
||||||
|
|
||||||
|
from graphene_django.forms.mutation import DjangoModelFormMutation
|
||||||
|
|
||||||
class Pet(models.Model):
|
class Pet(models.Model):
|
||||||
name = models.CharField()
|
name = models.CharField()
|
||||||
|
|
||||||
|
@ -61,8 +65,8 @@ Form validation
|
||||||
|
|
||||||
Form mutations will call ``is_valid()`` on your forms.
|
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
|
If the form is valid then the class method ``perform_mutate(form, info)`` is called on the mutation. Override this method
|
||||||
the form is saved or to return a different Graphene object type.
|
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
|
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.
|
containing the name of the invalid form field, and ``messages``, a list of strings with the validation messages.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user