diff --git a/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py new file mode 100644 index 0000000..f135392 --- /dev/null +++ b/examples/cookbook/cookbook/recipes/migrations/0002_auto_20161104_0106.py @@ -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), + ), + ] diff --git a/examples/cookbook/cookbook/recipes/models.py b/examples/cookbook/cookbook/recipes/models.py index 8e7f799..f666fe8 100644 --- a/examples/cookbook/cookbook/recipes/models.py +++ b/examples/cookbook/cookbook/recipes/models.py @@ -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=( diff --git a/examples/cookbook/cookbook/recipes/schema.py b/examples/cookbook/cookbook/recipes/schema.py index 0eff9e4..56379ab 100644 --- a/examples/cookbook/cookbook/recipes/schema.py +++ b/examples/cookbook/cookbook/recipes/schema.py @@ -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) diff --git a/examples/cookbook/cookbook/recipes/schema.py~ b/examples/cookbook/cookbook/recipes/schema.py~ new file mode 100644 index 0000000..6bd1541 --- /dev/null +++ b/examples/cookbook/cookbook/recipes/schema.py~ @@ -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)