errors in code

This commit is contained in:
chriscauley 2016-11-03 21:06:26 -04:00
parent ad063aa947
commit fa178a00ef
4 changed files with 61 additions and 3 deletions
examples/cookbook/cookbook/recipes

View File

@ -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),
),
]

View File

@ -9,7 +9,7 @@ class Recipe(models.Model):
__unicode__ = lambda self: self.title
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')
amount = models.FloatField()
unit = models.CharField(max_length=20, choices=(

View File

@ -20,9 +20,9 @@ class RecipeIngredientNode(DjangoObjectType):
filter_fields = {
'ingredient__name': ['exact', 'icontains', 'istartswith'],
'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):
recipe = Node.Field(RecipeNode)

View 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)