@@ -26,8 +26,8 @@ example app specifies [Django][django], [MySQL driver][mysql-driver] and
26
26
looks like this:
27
27
28
28
~~~
29
- Django==1.7.1
30
- gunicorn==19.1.1
29
+ Django==1.8.3
30
+ gunicorn==19.3
31
31
MySQL-python==1.2.5
32
32
~~~
33
33
@@ -60,13 +60,60 @@ Left from the colon we specified the **required** process type called `web`
60
60
followed by the command that starts the app and listens on the port specified
61
61
by the environment variable ` $PORT ` .
62
62
63
+ ### The Actual Application Code
64
+
65
+ The actual application code is straightforward. Each model is represented by a
66
+ class that subclasses django.db.models.Model. Each model has a number of class
67
+ variables, each of which represents a database field in the model.
68
+
69
+ Each field is represented by an instance of a Field class – e.g., CharField for
70
+ character fields and DateTimeField for datetimes. This tells Django what type of
71
+ data each field holds. Some of those Field classes, the CharField for example,
72
+ have required arguments
73
+
74
+ Finally, note a relationship is defined, using ForeignKey. That tells Django
75
+ each Choice is related to a single Question. Django supports all the common
76
+ database relationships: many-to-one, many-to-many and one-to-one.
77
+
78
+ ~~~ python
79
+ import datetime
80
+
81
+ from django.db import models
82
+ from django.utils import timezone
83
+
84
+
85
+ class Poll (models .Model ):
86
+ question = models.CharField(max_length = 200 )
87
+ pub_date = models.DateTimeField(' date published' )
88
+
89
+ def __unicode__ (self ):
90
+ return self .question
91
+
92
+ def was_published_recently (self ):
93
+ return self .pub_date >= timezone.now() - datetime.timedelta(days = 1 )
94
+
95
+ was_published_recently.admin_order_field = ' pub_date'
96
+ was_published_recently.boolean = True
97
+ was_published_recently.short_description = ' Published recently?'
98
+
99
+
100
+ class Choice (models .Model ):
101
+ poll = models.ForeignKey(Poll)
102
+ choice = models.CharField(max_length = 200 )
103
+ votes = models.IntegerField()
104
+
105
+ def __unicode__ (self ):
106
+ return self .choice
107
+ ~~~
108
+
63
109
### Production Database
64
110
65
111
The original tutorial application uses SQLite as the database in all
66
112
environments, even the production one. It is not possible to use a SQLite
67
113
database on cloudControl because the filesystem is
68
114
[ not persistent] [ filesystem ] . To use a database, you should choose an Add-on
69
- from [ the Data Storage category] [ data-storage-addons ] .
115
+ from [ the Data Storage category] [ data-storage-addons ] after creating and pushing
116
+ the application to cloudcontrol.
70
117
71
118
In this tutorial we use the [ Shared MySQL Add-on] [ mysqls ] . Have a look at
72
119
` mysite/settings.py ` so you can find out how to
@@ -109,7 +156,7 @@ DATABASES = {
109
156
## Pushing and Deploying your App
110
157
111
158
Choose a unique name to replace the ` APP_NAME ` placeholder for your
112
- application and create it on the cloudControl platform:
159
+ application and create it on the cloudControl platform:
113
160
114
161
~~~ bash
115
162
$ cctrlapp APP_NAME create python
@@ -119,36 +166,41 @@ Push your code to the application's repository, which triggers the deployment im
119
166
120
167
~~~ bash
121
168
$ cctrlapp APP_NAME push
122
- Counting objects: 49 , done.
169
+ Counting objects: 53 , done.
123
170
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
-
171
+ Compressing objects: 100% (44/44 ), done.
172
+ Writing objects: 100% (53/53 ), 9.33 KiB | 0 bytes/s, done.
173
+ Total 53 (delta 12 ), reused 0 (delta 0 )
174
+
128
175
-----> Receiving push
129
- -----> No runtime.txt provided; assuming python-2.7.3 .
130
- -----> Preparing Python runtime (python-2.7.3 )
176
+ -----> No runtime.txt provided; assuming python-2.7.8 .
177
+ -----> Preparing Python runtime (python-2.7.8 )
131
178
-----> Installing Distribute (0.6.36)
132
179
-----> Installing Pip (1.3.1)
133
180
-----> 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
181
+ Downloading/unpacking Django==1.8.3 (from -r requirements.txt (line 1))
136
182
...
137
- -----> Building image
138
- -----> Uploading image (29.9 MB)
183
+ Successfully installed Django gunicorn MySQL-python
184
+ Cleaning up...
185
+
186
+ -----> Building image
187
+ -----> Uploading image (28.8 MB)
139
188
140
189
To ssh://
[email protected] /repository.git
141
- * [new branch] master -> master
190
+ * [new branch] master -> master
142
191
~~~
143
192
144
- Add MySQLs Add-on with ` free ` plan to your deployment and deploy it:
193
+ Add MySQLs Add-on with 'free' plan to your deployment and deploy it:
194
+
145
195
~~~ bash
146
196
$ cctrlapp APP_NAME addon.add mysqls.free
147
197
$ cctrlapp APP_NAME deploy
148
198
~~~
149
199
200
+ ## Migrating the database
201
+
150
202
Finally, prepare the database using the
151
- [ Run command] [ ssh-session ] (when prompted create admin user):
203
+ [ Run command] [ ssh-session ] (when prompted you can create an admin user):
152
204
153
205
~~~ bash
154
206
$ cctrlapp APP_NAME run " python manage.py syncdb"
0 commit comments