Skip to content

Commit 77ef3a5

Browse files
committed
Update the Django documentation
Due to the outdated versions of the used Django version. The documentation need a rework to correct the dependencies. Add the missing Application code and explanations.
1 parent 8a50b66 commit 77ef3a5

File tree

1 file changed

+59
-18
lines changed

1 file changed

+59
-18
lines changed

Guides/Python/Django.md

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ example app specifies [Django][django], [MySQL driver][mysql-driver] and
2626
looks like this:
2727

2828
~~~
29-
Django==1.7.1
30-
gunicorn==19.1.1
29+
Django==1.8.3
30+
gunicorn==19.3
3131
MySQL-python==1.2.5
3232
~~~
3333

@@ -60,13 +60,49 @@ Left from the colon we specified the **required** process type called `web`
6060
followed by the command that starts the app and listens on the port specified
6161
by the environment variable `$PORT`.
6262

63+
### The Actual Application Code
64+
65+
The actual application code is taken from the [official Django tutorial](https://docs.djangoproject.com/en/1.8/intro/tutorial01/) and explains in detail how the applications works.
66+
67+
~~~python
68+
import datetime
69+
70+
from django.db import models
71+
from django.utils import timezone
72+
73+
74+
class Poll(models.Model):
75+
question = models.CharField(max_length=200)
76+
pub_date = models.DateTimeField('date published')
77+
78+
def __unicode__(self):
79+
return self.question
80+
81+
def was_published_recently(self):
82+
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
83+
84+
was_published_recently.admin_order_field = 'pub_date'
85+
was_published_recently.boolean = True
86+
was_published_recently.short_description = 'Published recently?'
87+
88+
89+
class Choice(models.Model):
90+
poll = models.ForeignKey(Poll)
91+
choice = models.CharField(max_length=200)
92+
votes = models.IntegerField()
93+
94+
def __unicode__(self):
95+
return self.choice
96+
~~~
97+
6398
### Production Database
6499

65100
The original tutorial application uses SQLite as the database in all
66101
environments, even the production one. It is not possible to use a SQLite
67102
database on cloudControl because the filesystem is
68103
[not persistent][filesystem]. To use a database, you should choose an Add-on
69-
from [the Data Storage category][data-storage-addons].
104+
from [the Data Storage category][data-storage-addons] after creating and pushing
105+
the application to cloudcontrol.
70106

71107
In this tutorial we use the [Shared MySQL Add-on][mysqls]. Have a look at
72108
`mysite/settings.py` so you can find out how to
@@ -109,7 +145,7 @@ DATABASES = {
109145
## Pushing and Deploying your App
110146

111147
Choose a unique name to replace the `APP_NAME` placeholder for your
112-
application and create it on the cloudControl platform:
148+
application and create it on the cloudControl platform:
113149

114150
~~~bash
115151
$ cctrlapp APP_NAME create python
@@ -119,36 +155,41 @@ Push your code to the application's repository, which triggers the deployment im
119155

120156
~~~bash
121157
$ cctrlapp APP_NAME push
122-
Counting objects: 49, done.
158+
Counting objects: 53, done.
123159
Delta compression using up to 8 threads.
124-
Compressing objects: 100% (33/33), done.
125-
Writing objects: 100% (49/49), 8.80 KiB | 0 bytes/s, done.
126-
Total 49 (delta 11), reused 38 (delta 8)
127-
160+
Compressing objects: 100% (44/44), done.
161+
Writing objects: 100% (53/53), 9.33 KiB | 0 bytes/s, done.
162+
Total 53 (delta 12), reused 0 (delta 0)
163+
128164
-----> Receiving push
129-
-----> No runtime.txt provided; assuming python-2.7.3.
130-
-----> Preparing Python runtime (python-2.7.3)
165+
-----> No runtime.txt provided; assuming python-2.7.8.
166+
-----> Preparing Python runtime (python-2.7.8)
131167
-----> Installing Distribute (0.6.36)
132168
-----> Installing Pip (1.3.1)
133169
-----> Installing dependencies using Pip (1.3.1)
134-
Downloading/unpacking Django==1.7.1 (from -r requirements.txt (line 1))
135-
Running setup.py egg_info for package Django
170+
Downloading/unpacking Django==1.8.3 (from -r requirements.txt (line 1))
136171
...
137-
-----> Building image
138-
-----> Uploading image (29.9 MB)
172+
Successfully installed Django gunicorn MySQL-python
173+
Cleaning up...
174+
175+
-----> Building image
176+
-----> Uploading image (28.8 MB)
139177

140178
To ssh://[email protected]/repository.git
141-
* [new branch] master -> master
179+
* [new branch] master -> master
142180
~~~
143181

144-
Add MySQLs Add-on with `free` plan to your deployment and deploy it:
182+
Add MySQLs Add-on with 'free' plan to your deployment and deploy it:
183+
145184
~~~bash
146185
$ cctrlapp APP_NAME addon.add mysqls.free
147186
$ cctrlapp APP_NAME deploy
148187
~~~
149188

189+
## Migrating the database
190+
150191
Finally, prepare the database using the
151-
[Run command][ssh-session] (when prompted create admin user):
192+
[Run command][ssh-session] (when prompted you can create an admin user):
152193

153194
~~~bash
154195
$ cctrlapp APP_NAME run "python manage.py syncdb"

0 commit comments

Comments
 (0)