Skip to content

Commit bbf1392

Browse files
committed
Improved Django documentation
1 parent 33ff3c5 commit bbf1392

File tree

3 files changed

+75
-27
lines changed

3 files changed

+75
-27
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/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

@@ -183,7 +209,7 @@ Installed 6 object(s) from 1 fixture(s)
183209
```
184210

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

189215
## Testing our GraphQL schema
@@ -235,22 +261,30 @@ query {
235261
edges {
236262
node {
237263
name,
238-
239264
ingredients {
240265
edges {
241266
node {
242267
name
243-
}}}}}}}
268+
}
269+
}
270+
}
271+
}
272+
}
273+
}
274+
}
244275
```
245276

246277
Or you can get only 'meat' ingredients containing the letter 'e':
247278

248279
```graphql
249280
query {
250281
# You can also use `category: "CATEGORY GLOBAL ID"`
251-
allIngredients(nameIcontains: "e", categoryName: "Meat") {
282+
allIngredients(name_Icontains: "e", categoryName: "Meat") {
252283
edges {
253284
node {
254285
name
255-
}}}}
286+
}
287+
}
288+
}
289+
}
256290
```

0 commit comments

Comments
 (0)