mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-13 17:52:19 +03:00
add DjangoFormMutation to cookbook example
This commit is contained in:
parent
917851bd97
commit
675a989c7c
15
examples/cookbook-plain/cookbook/ingredients/forms.py
Normal file
15
examples/cookbook-plain/cookbook/ingredients/forms.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django import forms
|
||||
from cookbook.ingredients.models import Category, Ingredient
|
||||
|
||||
|
||||
class CategoryForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Category
|
||||
exclude = []
|
||||
|
||||
|
||||
class IngredientForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Ingredient
|
||||
exclude = []
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
import graphene
|
||||
from graphene_django.types import DjangoObjectType
|
||||
from graphene_django.forms.mutation import DjangoFormMutation
|
||||
|
||||
from .models import Category, Ingredient
|
||||
from .forms import CategoryForm, IngredientForm
|
||||
|
||||
|
||||
class CategoryType(DjangoObjectType):
|
||||
|
@ -49,3 +51,18 @@ class Query(object):
|
|||
return Ingredient.objects.get(name=name)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class CategoryMutation(DjangoFormMutation):
|
||||
class Meta:
|
||||
form_class = CategoryForm
|
||||
|
||||
|
||||
class IngredientMutation(DjangoFormMutation):
|
||||
class Meta:
|
||||
form_class = IngredientForm
|
||||
|
||||
|
||||
class Mutation(object):
|
||||
category = CategoryMutation.Field()
|
||||
ingredient = IngredientMutation.Field()
|
||||
|
|
|
@ -11,4 +11,9 @@ class Query(cookbook.ingredients.schema.Query,
|
|||
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||
|
||||
|
||||
schema = graphene.Schema(query=Query)
|
||||
class Mutation(cookbook.ingredients.schema.Mutation,
|
||||
graphene.ObjectType):
|
||||
pass
|
||||
|
||||
|
||||
schema = graphene.Schema(query=Query, mutation=Mutation)
|
||||
|
|
Loading…
Reference in New Issue
Block a user