Skip to content

Commit d763bf9

Browse files
committed
Merge pull request #128 from amsb/master
Updated django quickstart tutorial
2 parents b5f343b + c67990d commit d763bf9

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

docs/pages/docs/django/tutorial.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ class Query(ObjectType):
130130
The filtering functionality is provided by
131131
[django-filter](https://django-filter.readthedocs.org). See the
132132
[usage documentation](https://django-filter.readthedocs.org/en/latest/usage.html#the-filter)
133-
for details on the format for `filter_fields`.
133+
for details on the format for `filter_fields`. While optional, this tutorial makes use of this functionality so you will need to install `django-filter` for this tutorial to work:
134+
135+
````bash
136+
pip install django-filter
137+
```
134138

135139
Note that the above `Query` class is marked as 'abstract'. This is because we
136140
will now create a project-level query which will combine all our app-level
@@ -156,13 +160,15 @@ schema.query = Query
156160
You can think of this as being something like your top-level `urls.py`
157161
file (although it currently lacks any namespacing).
158162

159-
## Adding GraphiQL
163+
## Update `INSTALLED_APPS`
160164

161-
GraphiQL is a web-based integrated development environment to assist in the
162-
writing and executing of GraphQL queries. It will provide us with a simple
163-
and easy way of testing our cookbook project.
165+
Next, install your app and GraphiQL in your Django project. GraphiQL is
166+
a web-based integrated development environment to assist in the writing and
167+
executing of GraphQL queries. It will provide us with a simple and easy way
168+
of testing our cookbook project.
164169

165-
Add `django_graphiql` to `INSTALLED_APPS` in `cookbook/settings.py`:
170+
Add `ingredients`, `graphene.contrib.django` and `django_graphiql` to
171+
`INSTALLED_APPS` in `cookbook/settings.py`:
166172

167173
```python
168174
INSTALLED_APPS = [
@@ -171,9 +177,13 @@ INSTALLED_APPS = [
171177
172178
# This will also make the `graphql_schema` management command available
173179
'graphene.contrib.django',
180+
181+
# Install the ingredients app
182+
'ingredients',
174183
]
175184
```
176185

186+
177187
## Creating GraphQL and GraphiQL views
178188

179189
Unlike a RESTful API, there is only a single URL from which GraphQL is accessed.
@@ -198,10 +208,19 @@ urlpatterns = [
198208
]
199209
```
200210

211+
## Apply model changes to database
212+
213+
Tell Django that we've added models and update the database schema to reflect these additions.
214+
215+
```bash
216+
python manage.py makemigrations
217+
python manage.py migrate
218+
```
219+
201220
## Load some test data
202221
203222
Now is a good time to load up some test data. The easiest option will be to
204-
[download the ingredients.json](https://raw.githubusercontent.com/graphql-python/graphene/feature/django/examples/cookbook/cookbook/ingredients/fixtures/ingredients.json)
223+
[download the ingredients.json](https://raw.githubusercontent.com/graphql-python/graphene/master/examples/cookbook_django/cookbook/ingredients/fixtures/ingredients.json)
205224
fixture and place it in
206225
`cookbook/ingredients/fixtures/ingredients.json`. You can then run the following:
207226
@@ -211,7 +230,7 @@ $ python ./manage.py loaddata ingredients
211230
Installed 6 object(s) from 1 fixture(s)
212231
```
213232
214-
Alternatively you can use the Django admin interface to create some data youself.
233+
Alternatively you can use the Django admin interface to create some data yourself.
215234
You'll need to run the development server (see below), and create a login
216235
for yourself too (`./manage.py createsuperuser`).
217236

@@ -282,7 +301,7 @@ Or you can get only 'meat' ingredients containing the letter 'e':
282301
```graphql
283302
query {
284303
# You can also use `category: "CATEGORY GLOBAL ID"`
285-
allIngredients(name_Icontains: "e", categoryName: "Meat") {
304+
allIngredients(name_Icontains: "e", category_Name: "Meat") {
286305
edges {
287306
node {
288307
name

0 commit comments

Comments
 (0)