Skip to content

Commit 3bb0e6c

Browse files
committed
Merge branch 'refs/heads/feature/django'
2 parents b18fbb5 + bbf1392 commit 3bb0e6c

File tree

4 files changed

+80
-30
lines changed

4 files changed

+80
-30
lines changed

docs/config.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ga = "UA-12613282-7"
55
name = "Quickstart"
66
pages = [
77
"/docs/quickstart/",
8-
"/docs/quickstart-django/",
98
]
109

1110
[docs.walkthrough]
@@ -16,5 +15,11 @@ ga = "UA-12613282-7"
1615
"/docs/mutations/",
1716
"/docs/basic-types/",
1817
"/docs/relay/",
19-
"/docs/filtering/",
18+
]
19+
20+
[docs.django]
21+
name = "Django"
22+
pages = [
23+
"/docs/django/tutorial/",
24+
"/docs/django/filtering/",
2025
]

docs/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
"copy-webpack-plugin": "^0.2.0",
1818
"es6-promise": "^3.0.2",
1919
"extract-text-webpack-plugin": "^0.9.1",
20-
"gatsby": "^0.7.3",
20+
"gatsby": "^0.7.7",
2121
"graphiql": "^0.4.2",
2222
"graphql": "^0.4.13",
2323
"jeet": "^6.1.2",
2424
"lodash": "^3.10.1",
2525
"nib": "^1.1.0",
26-
"react": "^0.14.3",
27-
"react-burger-menu": "^1.4.2",
26+
"react": "^0.14.6",
27+
"radium": "0.14.2",
28+
"react-burger-menu": "^1.4.12",
2829
"react-document-title": "^2.0.1",
30+
"react-dom": "^0.14.6",
2931
"react-router": "^0.13.5",
3032
"rupture": "^0.6.1",
3133
"stylus-loader": "^1.4.2",

docs/pages/docs/filtering.md renamed to docs/pages/docs/django/filtering.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: Filtering (Django)
3-
description: Details of how to perform filtering
2+
title: Filtering
3+
description: Details of how to perform filtering in Graphene Django
44
---
55

6-
# Filtering (Django)
6+
# Filtering
77

88
Graphene integrates with [django-filter](https://django-filter.readthedocs.org)
99
to provide filtering of results. See the
@@ -21,7 +21,7 @@ pip install django-filter
2121
```
2222

2323
**Note: The techniques below are demoed in the
24-
[cookbook example app](https://github.com/graphql-python/graphene/tree/feature/django/examples/cookbook).**
24+
[cookbook example app](https://github.com/graphql-python/graphene/tree/master/examples/cookbook_django).**
2525

2626
## Filterable fields
2727

@@ -54,7 +54,10 @@ query {
5454
node {
5555
id,
5656
name
57-
}}}}
57+
}
58+
}
59+
}
60+
}
5861
```
5962

6063
You can also make more complex lookup types available:
@@ -76,12 +79,15 @@ Which you could query as follows:
7679
```graphql
7780
query {
7881
# Note that fields names become camelcased
79-
allAnimals(nameIcontains: "lion") {
82+
allAnimals(name_Icontains: "lion") {
8083
edges {
8184
node {
8285
id,
8386
name
84-
}}}}
87+
}
88+
}
89+
}
90+
}
8591
```
8692

8793
## Orderable fields
@@ -112,7 +118,10 @@ query {
112118
node {
113119
id,
114120
name
115-
}}}}
121+
}
122+
}
123+
}
124+
}
116125
```
117126

118127
## Custom Filtersets

docs/pages/docs/quickstart-django.md renamed to docs/pages/docs/django/tutorial.md

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,54 @@
11
---
2-
title: Django Quickstart
2+
title: Quickstart
33
description: A Quick guide to Graphene in Django
44
---
55

66
# Django Tutorial
77

88
Graphene has a number of additional features that are designed to make
9-
working with Django simple.
10-
11-
If you need help getting started with django then head over to
12-
Django's getting started page.
13-
14-
First let's create a few simple models...
9+
working with Django *really simple*.
1510

1611
**Note: The code in this quickstart is pulled from the
17-
[cookbook example app](https://github.com/graphql-python/graphene/tree/feature/django/examples/cookbook)**.
12+
[cookbook example app](https://github.com/graphql-python/graphene/tree/master/examples/cookbook_django)**.
1813

19-
## Defining our models
2014

21-
Before continuing, create the following:
15+
## Setup the Django project
16+
17+
We will setup the project, create the following:
2218

2319
* A Django project called `cookbook`
2420
* An app within `cookbook` called `ingredients`
2521

22+
```bash
23+
# Create the project directory
24+
mkdir cookbook
25+
cd cookbook
26+
27+
# Create a virtualenv to isolate our package dependencies locally
28+
virtualenv env
29+
source env/bin/activate # On Windows use `env\Scripts\activate`
30+
31+
# Install Django and Graphene with Django support
32+
pip install django
33+
pip install graphene[django]
34+
pip install django-graphiql
35+
36+
# Set up a new project with a single application
37+
django-admin.py startproject cookbook . # Note the trailing '.' character
38+
django-admin.py startapp ingredients
39+
```
40+
41+
Now sync your database for the first time:
42+
43+
```bash
44+
python manage.py migrate
45+
```
46+
47+
Let's create a few simple models...
48+
49+
50+
## Defining our models
51+
2652
Let's get started with these models:
2753

2854
```python
@@ -51,9 +77,9 @@ class Ingredient(models.Model):
5177
GraphQL presents your objects to the world as a graph structure rather than a more
5278
hierarchical structure to which you may be accustomed. In order to create this
5379
representation, Graphene needs to know about each *type* of object which will appear in
54-
the graph. Below we define these as the `UserType` and `GroupType` classes.
80+
the graph.
5581

56-
This graph also has a 'root' through which all access begins. This is the `Query` class below.
82+
This graph also has a *root type* through which all access begins. This is the `Query` class below.
5783
In this example, we provide the ability to list all users via `all_users`, and the
5884
ability to obtain a specific user via `get_user`.
5985

@@ -186,7 +212,7 @@ Installed 6 object(s) from 1 fixture(s)
186212
```
187213

188214
Alternatively you can use the Django admin interface to create some data youself.
189-
You'll need to run the development server (see below), and probably create a login
215+
You'll need to run the development server (see below), and create a login
190216
for yourself too (`./manage.py createsuperuser`).
191217

192218
## Testing our GraphQL schema
@@ -238,22 +264,30 @@ query {
238264
edges {
239265
node {
240266
name,
241-
242267
ingredients {
243268
edges {
244269
node {
245270
name
246-
}}}}}}}
271+
}
272+
}
273+
}
274+
}
275+
}
276+
}
277+
}
247278
```
248279

249280
Or you can get only 'meat' ingredients containing the letter 'e':
250281

251282
```graphql
252283
query {
253284
# You can also use `category: "CATEGORY GLOBAL ID"`
254-
allIngredients(nameIcontains: "e", categoryName: "Meat") {
285+
allIngredients(name_Icontains: "e", categoryName: "Meat") {
255286
edges {
256287
node {
257288
name
258-
}}}}
289+
}
290+
}
291+
}
292+
}
259293
```

0 commit comments

Comments
 (0)