Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix from-scratch tutorial #573

Merged
merged 5 commits into from Jan 29, 2021
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 43 additions & 7 deletions examples/from-scratch/README.md
Expand Up @@ -2,12 +2,19 @@

This example shows how to use django-spanner for Cloud Spanner as a backend database for [Django's tutorials](https://docs.djangoproject.com/en/2.2/intro/tutorial01/)

*NOTE:* Use the version of python-spanner-django that corresponds to your version of Django. For example, python-spanner-django 2.2.x works with Django 2.2.y. (This is the only supported version at this time.)

### Walkthrough the introduction to Django

### Install django-spanner
We'll need to install `django-spanner`, by cloning this repository and then running `pip3 install`
To install from PyPI:
```shell
pip3 install django-google-spanner
```
To install from source:
```shell
git clone https://github.com/googleapis/django-spanner
git clone https://github.com/googleapis/python-spanner-django
cd python-spanner-django/
pip3 install .
```

Expand All @@ -26,7 +33,7 @@ After we have a Cloud Spanner database created, we'll need a few variables:
* Instance name
* Database name aka DisplayName

Once in, please edit the file `hc/local_settings.py`, and:
Once in, edit the DATABASES section of your mysite/settings.py file to the following:

a) add `django_spanner` as the very first entry to your `INSTALLED_APPS`
```python
Expand All @@ -51,8 +58,8 @@ DATABASES = {
and for example here is a filled in database where:

* `PROJECT_ID`: spanner-appdev
* INSTANCE: instance
* NAME: `healthchecks_db`
* `INSTANCE`: instance
* `NAME`: db1

which when filled out, will look like this

Expand All @@ -62,11 +69,17 @@ DATABASES = {
'ENGINE': 'django_spanner',
'PROJECT': 'spanner-appdev',
'INSTANCE': 'instance',
'NAME': 'healthchecks_db',
'NAME': 'db1',
}
}
```

### Set Google Application Default Credentials to the environment
You'll need to download a service account JSON key file and point to it using an environment variable:
```shell
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/keyfile.json
```

### Apply the migrations
Please run:
```shell
Expand Down Expand Up @@ -102,13 +115,36 @@ Running migrations:
```
</details>

After this you should can see the tables and indices created in your Cloud Spanner console

### Now run your server
After those migrations are completed, that will be all. Please continue on with the guides.

### Create an Django admin user
First you’ll need to create a user who can login to the admin site. Run the following command:

```shell
$ python3 manage.py createsuperuser
```
which will then produce a prompt which will allow you to create your super user
```shell
Username: admin
Email address: admin@example.com
Password: **********
Password (again): **********
Superuser created successfully.
```

### Login as admin
Let’s run the server
```shell script
python3 manage.py runserver
```
Then visit http://127.0.0.1:8000/admin/

### Comprehensive hands-on guide
For a more comprehensive, step by step hands-on guide, please visit [using django-spanner from scratch](https://orijtech-161805.firebaseapp.com/quickstart/new_app/)


### References

Resource|URL
Expand Down