Skip to content

Commit a4e225d

Browse files
committed
Initial work on new django docs
1 parent be6b2bf commit a4e225d

File tree

1 file changed

+16
-42
lines changed

1 file changed

+16
-42
lines changed

docs/pages/docs/quickstart-django.md

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,31 @@ description: A Quick guide to Graphene in Django
55

66
# Django Tutorial
77

8-
In our previous quickstart page we created a very simple schema.
8+
Graphene has a number of additional features that are designed to make
9+
working with Django simple.
910

10-
Now we will adapt the schema to automatically map some Django models,
11-
and expose this schema in a `/graphql` API endpoint.
11+
If you need help getting started with django then head over to
12+
Django's getting started page.
1213

13-
## Project setup
14+
First let's create a few simple models
1415

15-
```bash
16-
# Create the project directory
17-
mkdir tutorial
18-
cd tutorial
19-
20-
# Create a virtualenv to isolate our package dependencies locally
21-
virtualenv env
22-
source env/bin/activate # On Windows use `env\Scripts\activate`
23-
24-
# Install Django and Graphene with Django support
25-
pip install django
26-
pip install graphene[django]
27-
pip install django-graphiql
28-
29-
# Set up a new project with a single application
30-
django-admin.py startproject tutorial . # Note the trailing '.' character
31-
django-admin.py startapp quickstart
32-
```
33-
34-
Now sync your database for the first time:
16+
## Some models
3517

36-
```bash
37-
python manage.py migrate
38-
```
18+
Let's get started with these models **in an app called ingredients**:
3919

40-
We'll also create an initial user named `admin` with a password of `password`.
20+
```python
21+
# cookbook/ingredients/models.py
22+
from django.db import models
4123

42-
```bash
43-
python manage.py createsuperuser
44-
```
4524

46-
Once you've set up a database and initial user created and ready to go, open up the app's directory and we'll get coding...
25+
class Category(models.Model):
26+
name = models.CharField(max_length=100)
4727

4828

29+
class Ingredient(models.Model):
30+
name = models.CharField(max_length=100)
31+
category = models.ForeignKey(Category)
32+
```
4933

5034
## Schema
5135

@@ -81,21 +65,11 @@ class GroupType(DjangoObjectType):
8165

8266

8367
class Query(graphene.ObjectType):
84-
all_users = graphene.List(UserType)
8568
get_user = graphene.Field(UserType,
8669
id=graphene.String().NonNull)
8770
get_group = graphene.Field(GroupType,
8871
id=graphene.String().NonNull)
8972

90-
def resolve_all_users(self, args, info):
91-
return User.objects.all()
92-
93-
def resolve_get_user(self, args, info):
94-
return User.objects.get(id=args.get('id'))
95-
96-
def resolve_get_group(self, args, info):
97-
return Group.objects.get(id=args.get('id'))
98-
9973
schema = graphene.Schema(query=Query)
10074
```
10175

0 commit comments

Comments
 (0)