mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-22 09:37:07 +03:00
Make examples diff better against each other
This commit is contained in:
parent
1755948768
commit
a97729d362
|
@ -3,7 +3,7 @@ Cookbook Example Django Project
|
||||||
|
|
||||||
This example project demos integration between Graphene and Django.
|
This example project demos integration between Graphene and Django.
|
||||||
The project contains two apps, one named `ingredients` and another
|
The project contains two apps, one named `ingredients` and another
|
||||||
named `recepies`.
|
named `recipes`.
|
||||||
|
|
||||||
Getting started
|
Getting started
|
||||||
---------------
|
---------------
|
||||||
|
|
2
examples/cookbook-plain/cookbook/ingredients/tests.py
Normal file
2
examples/cookbook-plain/cookbook/ingredients/tests.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
# Create your tests here.
|
2
examples/cookbook-plain/cookbook/ingredients/views.py
Normal file
2
examples/cookbook-plain/cookbook/ingredients/views.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
# Create your views here.
|
|
@ -6,6 +6,7 @@ from cookbook.ingredients.models import Ingredient
|
||||||
class Recipe(models.Model):
|
class Recipe(models.Model):
|
||||||
title = models.CharField(max_length=100)
|
title = models.CharField(max_length=100)
|
||||||
instructions = models.TextField()
|
instructions = models.TextField()
|
||||||
|
__unicode__ = lambda self: self.title
|
||||||
|
|
||||||
|
|
||||||
class RecipeIngredient(models.Model):
|
class RecipeIngredient(models.Model):
|
||||||
|
|
2
examples/cookbook-plain/cookbook/recipes/tests.py
Normal file
2
examples/cookbook-plain/cookbook/recipes/tests.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
# Create your tests here.
|
2
examples/cookbook-plain/cookbook/recipes/views.py
Normal file
2
examples/cookbook-plain/cookbook/recipes/views.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
# Create your views here.
|
|
@ -2,9 +2,11 @@ from django.contrib import admin
|
||||||
|
|
||||||
from cookbook.ingredients.models import Category, Ingredient
|
from cookbook.ingredients.models import Category, Ingredient
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Ingredient)
|
@admin.register(Ingredient)
|
||||||
class IngredientAdmin(admin.ModelAdmin):
|
class IngredientAdmin(admin.ModelAdmin):
|
||||||
list_display = ("id","name","category")
|
list_display = ('id', 'name', 'category')
|
||||||
list_editable = ("name","category")
|
list_editable = ('name', 'category')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Category)
|
admin.site.register(Category)
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Category(models.Model):
|
||||||
|
|
||||||
class Ingredient(models.Model):
|
class Ingredient(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
notes = models.TextField(null=True,blank=True)
|
notes = models.TextField(null=True, blank=True)
|
||||||
category = models.ForeignKey(Category, related_name='ingredients')
|
category = models.ForeignKey(Category, related_name='ingredients')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -2,9 +2,11 @@ from django.contrib import admin
|
||||||
|
|
||||||
from cookbook.recipes.models import Recipe, RecipeIngredient
|
from cookbook.recipes.models import Recipe, RecipeIngredient
|
||||||
|
|
||||||
|
|
||||||
class RecipeIngredientInline(admin.TabularInline):
|
class RecipeIngredientInline(admin.TabularInline):
|
||||||
model = RecipeIngredient
|
model = RecipeIngredient
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Recipe)
|
@admin.register(Recipe)
|
||||||
class RecipeAdmin(admin.ModelAdmin):
|
class RecipeAdmin(admin.ModelAdmin):
|
||||||
inlines = [RecipeIngredientInline]
|
inlines = [RecipeIngredientInline]
|
||||||
|
|
|
@ -8,6 +8,7 @@ class Recipe(models.Model):
|
||||||
instructions = models.TextField()
|
instructions = models.TextField()
|
||||||
__unicode__ = lambda self: self.title
|
__unicode__ = lambda self: self.title
|
||||||
|
|
||||||
|
|
||||||
class RecipeIngredient(models.Model):
|
class RecipeIngredient(models.Model):
|
||||||
recipe = 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')
|
||||||
|
|
|
@ -5,7 +5,9 @@ import graphene
|
||||||
from graphene_django.debug import DjangoDebug
|
from graphene_django.debug import DjangoDebug
|
||||||
|
|
||||||
|
|
||||||
class Query(cookbook.recipes.schema.Query, cookbook.ingredients.schema.Query, graphene.ObjectType):
|
class Query(cookbook.ingredients.schema.Query,
|
||||||
|
cookbook.recipes.schema.Query,
|
||||||
|
graphene.ObjectType):
|
||||||
debug = graphene.Field(DjangoDebug, name='__debug')
|
debug = graphene.Field(DjangoDebug, name='__debug')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# flake8: noqa
|
||||||
"""
|
"""
|
||||||
Django settings for cookbook project.
|
Django settings for cookbook project.
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from django.contrib import admin
|
||||||
|
|
||||||
from graphene_django.views import GraphQLView
|
from graphene_django.views import GraphQLView
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
|
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
|
||||||
|
|
2
examples/cookbook/setup.cfg
Normal file
2
examples/cookbook/setup.cfg
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[flake8]
|
||||||
|
exclude=migrations,.git,__pycache__
|
Loading…
Reference in New Issue
Block a user