Skip to content

Commit 6ce59ae

Browse files
authored
Merge pull request #538 from alqinae/cookbook-plain-2.1-compatible
Cookbook plain 2.1.2 compatible
2 parents 297b807 + 905b424 commit 6ce59ae

File tree

9 files changed

+58
-32
lines changed

9 files changed

+58
-32
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Generated by Django 2.0 on 2018-10-18 17:46
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('ingredients', '0002_auto_20161104_0050'),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name='category',
15+
options={'verbose_name_plural': 'Categories'},
16+
),
17+
]

examples/cookbook-plain/cookbook/ingredients/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
class Category(models.Model):
5+
class Meta:
6+
verbose_name_plural = 'Categories'
57
name = models.CharField(max_length=100)
68

79
def __str__(self):
@@ -11,7 +13,7 @@ def __str__(self):
1113
class Ingredient(models.Model):
1214
name = models.CharField(max_length=100)
1315
notes = models.TextField(null=True, blank=True)
14-
category = models.ForeignKey(Category, related_name='ingredients')
16+
category = models.ForeignKey(Category, related_name='ingredients', on_delete=models.CASCADE)
1517

1618
def __str__(self):
1719
return self.name

examples/cookbook-plain/cookbook/ingredients/schema.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import graphene
22
from graphene_django.types import DjangoObjectType
33

4-
from cookbook.ingredients.models import Category, Ingredient
4+
from .models import Category, Ingredient
55

66

77
class CategoryType(DjangoObjectType):
@@ -25,17 +25,14 @@ class Query(object):
2525
name=graphene.String())
2626
all_ingredients = graphene.List(IngredientType)
2727

28-
def resolve_all_categories(self, args, context, info):
28+
def resolve_all_categories(self, context):
2929
return Category.objects.all()
3030

31-
def resolve_all_ingredients(self, args, context, info):
31+
def resolve_all_ingredients(self, context):
3232
# We can easily optimize query count in the resolve method
3333
return Ingredient.objects.select_related('category').all()
3434

35-
def resolve_category(self, args, context, info):
36-
id = args.get('id')
37-
name = args.get('name')
38-
35+
def resolve_category(self, context, id=None, name=None):
3936
if id is not None:
4037
return Category.objects.get(pk=id)
4138

@@ -44,10 +41,7 @@ def resolve_category(self, args, context, info):
4441

4542
return None
4643

47-
def resolve_ingredient(self, args, context, info):
48-
id = args.get('id')
49-
name = args.get('name')
50-
44+
def resolve_ingredient(self, context, id=None, name=None):
5145
if id is not None:
5246
return Ingredient.objects.get(pk=id)
5347

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 2.0 on 2018-10-18 17:28
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('recipes', '0002_auto_20161104_0106'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='recipeingredient',
15+
name='unit',
16+
field=models.CharField(choices=[('unit', 'Units'), ('kg', 'Kilograms'), ('l', 'Litres'), ('st', 'Shots')], max_length=20),
17+
),
18+
]

examples/cookbook-plain/cookbook/recipes/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
from django.db import models
22

3-
from cookbook.ingredients.models import Ingredient
3+
from ..ingredients.models import Ingredient
44

55

66
class Recipe(models.Model):
77
title = models.CharField(max_length=100)
88
instructions = models.TextField()
9-
__unicode__ = lambda self: self.title
9+
def __str__(self):
10+
return self.title
1011

1112

1213
class RecipeIngredient(models.Model):
13-
recipe = models.ForeignKey(Recipe, related_name='amounts')
14-
ingredient = models.ForeignKey(Ingredient, related_name='used_by')
14+
recipe = models.ForeignKey(Recipe, related_name='amounts', on_delete=models.CASCADE)
15+
ingredient = models.ForeignKey(Ingredient, related_name='used_by', on_delete=models.CASCADE)
1516
amount = models.FloatField()
1617
unit = models.CharField(max_length=20, choices=(
1718
('unit', 'Units'),

examples/cookbook-plain/cookbook/recipes/schema.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import graphene
22
from graphene_django.types import DjangoObjectType
33

4-
from cookbook.recipes.models import Recipe, RecipeIngredient
4+
from .models import Recipe, RecipeIngredient
55

66

77
class RecipeType(DjangoObjectType):
@@ -24,10 +24,7 @@ class Query(object):
2424
id=graphene.Int())
2525
all_recipeingredients = graphene.List(RecipeIngredientType)
2626

27-
def resolve_recipe(self, args, context, info):
28-
id = args.get('id')
29-
title = args.get('title')
30-
27+
def resolve_recipe(self, context, id=None, title=None):
3128
if id is not None:
3229
return Recipe.objects.get(pk=id)
3330

@@ -36,17 +33,15 @@ def resolve_recipe(self, args, context, info):
3633

3734
return None
3835

39-
def resolve_recipeingredient(self, args, context, info):
40-
id = args.get('id')
41-
36+
def resolve_recipeingredient(self, context, id=None):
4237
if id is not None:
4338
return RecipeIngredient.objects.get(pk=id)
4439

4540
return None
4641

47-
def resolve_all_recipes(self, args, context, info):
42+
def resolve_all_recipes(self, context):
4843
return Recipe.objects.all()
4944

50-
def resolve_all_recipeingredients(self, args, context, info):
45+
def resolve_all_recipeingredients(self, context):
5146
related = ['recipe', 'ingredient']
5247
return RecipeIngredient.objects.select_related(*related).all()

examples/cookbook-plain/cookbook/settings.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@
4444
'cookbook.recipes.apps.RecipesConfig',
4545
]
4646

47-
MIDDLEWARE_CLASSES = [
47+
MIDDLEWARE = [
4848
'django.middleware.security.SecurityMiddleware',
4949
'django.contrib.sessions.middleware.SessionMiddleware',
5050
'django.middleware.common.CommonMiddleware',
5151
'django.middleware.csrf.CsrfViewMiddleware',
5252
'django.contrib.auth.middleware.AuthenticationMiddleware',
53-
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
5453
'django.contrib.messages.middleware.MessageMiddleware',
5554
'django.middleware.clickjacking.XFrameOptionsMiddleware',
5655
]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from django.conf.urls import url
1+
from django.urls import path
22
from django.contrib import admin
33

44
from graphene_django.views import GraphQLView
55

66

77
urlpatterns = [
8-
url(r'^admin/', admin.site.urls),
9-
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
8+
path('admin/', admin.site.urls),
9+
path('graphql/', GraphQLView.as_view(graphiql=True)),
1010
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
graphene
22
graphene-django
33
graphql-core>=2.1rc1
4-
django==1.9
4+
django==2.1.2

0 commit comments

Comments
 (0)