Browse Source

Make cookbook example working on django 2 (#680)

pull/681/head
Semyon Pupkov 3 years ago committed by Paul Hallett
parent
commit
91c1278d1a
  1. 4
      examples/cookbook/cookbook/ingredients/models.py
  2. 6
      examples/cookbook/cookbook/recipes/models.py
  3. 3
      examples/cookbook/cookbook/settings.py
  4. 2
      examples/cookbook/requirements.txt

4
examples/cookbook/cookbook/ingredients/models.py

@ -11,7 +11,9 @@ class Category(models.Model):
class Ingredient(models.Model):
name = models.CharField(max_length=100)
notes = models.TextField(null=True, blank=True)
category = models.ForeignKey(Category, related_name="ingredients")
category = models.ForeignKey(
Category, related_name="ingredients", on_delete=models.CASCADE
)
def __str__(self):
return self.name

6
examples/cookbook/cookbook/recipes/models.py

@ -10,8 +10,10 @@ class Recipe(models.Model):
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe, related_name="amounts")
ingredient = models.ForeignKey(Ingredient, related_name="used_by")
recipe = models.ForeignKey(Recipe, related_name="amounts", on_delete=models.CASCADE)
ingredient = models.ForeignKey(
Ingredient, related_name="used_by", on_delete=models.CASCADE
)
amount = models.FloatField()
unit = models.CharField(
max_length=20,

3
examples/cookbook/cookbook/settings.py

@ -43,13 +43,12 @@ INSTALLED_APPS = [
"cookbook.recipes.apps.RecipesConfig",
]
MIDDLEWARE_CLASSES = [
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.auth.middleware.SessionAuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

2
examples/cookbook/requirements.txt

@ -1,5 +1,5 @@
graphene
graphene-django
graphql-core>=2.1rc1
django==1.11.21
django==2.2.2
django-filter>=2

Loading…
Cancel
Save