mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-20 21:40:36 +03:00
errors in code
This commit is contained in:
parent
ad063aa947
commit
fa178a00ef
|
@ -0,0 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.9 on 2016-11-04 01:06
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('recipes', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='recipeingredient',
|
||||||
|
old_name='recipes',
|
||||||
|
new_name='recipe',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='recipeingredient',
|
||||||
|
name='unit',
|
||||||
|
field=models.CharField(choices=[(b'unit', b'Units'), (b'kg', b'Kilograms'), (b'l', b'Litres'), (b'st', b'Shots')], max_length=20),
|
||||||
|
),
|
||||||
|
]
|
|
@ -9,7 +9,7 @@ class Recipe(models.Model):
|
||||||
__unicode__ = lambda self: self.title
|
__unicode__ = lambda self: self.title
|
||||||
|
|
||||||
class RecipeIngredient(models.Model):
|
class RecipeIngredient(models.Model):
|
||||||
recipes = models.ForeignKey(Recipe, related_name='amounts')
|
recipe = models.ForeignKey(Recipe, related_name='amounts')
|
||||||
ingredient = models.ForeignKey(Ingredient, related_name='used_by')
|
ingredient = models.ForeignKey(Ingredient, related_name='used_by')
|
||||||
amount = models.FloatField()
|
amount = models.FloatField()
|
||||||
unit = models.CharField(max_length=20, choices=(
|
unit = models.CharField(max_length=20, choices=(
|
||||||
|
|
|
@ -20,9 +20,9 @@ class RecipeIngredientNode(DjangoObjectType):
|
||||||
filter_fields = {
|
filter_fields = {
|
||||||
'ingredient__name': ['exact', 'icontains', 'istartswith'],
|
'ingredient__name': ['exact', 'icontains', 'istartswith'],
|
||||||
'recipe': ['exact'],
|
'recipe': ['exact'],
|
||||||
'recipe__name': ['icontains'],
|
'recipe__title': ['icontains'],
|
||||||
}
|
}
|
||||||
filter_order_by = ['ingredient__name', 'recipe__name',]
|
filter_order_by = ['ingredient__name', 'recipe__title',]
|
||||||
|
|
||||||
class Query(AbstractType):
|
class Query(AbstractType):
|
||||||
recipe = Node.Field(RecipeNode)
|
recipe = Node.Field(RecipeNode)
|
||||||
|
|
33
examples/cookbook/cookbook/recipes/schema.py~
Normal file
33
examples/cookbook/cookbook/recipes/schema.py~
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
from cookbook.ingredients.models import Recipe, Ingredient
|
||||||
|
from graphene import AbstractType, Node
|
||||||
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
|
class RecipeNode(DjangoObjectType):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Recipe
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = ['name', 'ingredients']
|
||||||
|
filter_order_by = ['name']
|
||||||
|
|
||||||
|
class RecipeIngredientNode(DjangoObjectType):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = RecipeIngredient
|
||||||
|
# Allow for some more advanced filtering here
|
||||||
|
interfaces = (Node, )
|
||||||
|
filter_fields = {
|
||||||
|
'name': ['exact', 'icontains', 'istartswith'],
|
||||||
|
'notes': ['exact', 'icontains'],
|
||||||
|
'recipe': ['exact'],
|
||||||
|
'recipe__name': ['icontains'],
|
||||||
|
}
|
||||||
|
filter_order_by = ['name', 'recipe__name',]
|
||||||
|
|
||||||
|
class Query(AbstractType):
|
||||||
|
recipe = Node.Field(RecipeNode)
|
||||||
|
all_categories = DjangoFilterConnectionField(RecipeNode)
|
||||||
|
|
||||||
|
recipeingredient = Node.Field(IngredientNode)
|
||||||
|
all_recipeingredients = DjangoFilterConnectionField(RecipeIngredientNode)
|
Loading…
Reference in New Issue
Block a user