@@ -26,8 +26,8 @@ example app specifies [Django][django], [MySQL driver][mysql-driver] and
2626looks like this:
2727
2828~~~
29- Django==1.7.1
30- gunicorn==19.1.1
29+ Django==1.8.3
30+ gunicorn==19.3
3131MySQL-python==1.2.5
3232~~~
3333
@@ -60,13 +60,60 @@ Left from the colon we specified the **required** process type called `web`
6060followed by the command that starts the app and listens on the port specified
6161by the environment variable ` $PORT ` .
6262
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+
63109### Production Database
64110
65111The original tutorial application uses SQLite as the database in all
66112environments, even the production one. It is not possible to use a SQLite
67113database on cloudControl because the filesystem is
68114[ 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.
70117
71118In this tutorial we use the [ Shared MySQL Add-on] [ mysqls ] . Have a look at
72119` mysite/settings.py ` so you can find out how to
@@ -109,7 +156,7 @@ DATABASES = {
109156## Pushing and Deploying your App
110157
111158Choose 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:
113160
114161~~~ bash
115162$ cctrlapp APP_NAME create python
@@ -119,36 +166,41 @@ Push your code to the application's repository, which triggers the deployment im
119166
120167~~~ bash
121168$ cctrlapp APP_NAME push
122- Counting objects: 49 , done.
169+ Counting objects: 53 , done.
123170Delta 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+
128175-----> 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 )
131178-----> Installing Distribute (0.6.36)
132179-----> Installing Pip (1.3.1)
133180-----> 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))
136182 ...
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)
139188
140189To ssh://APP_NAME@cloudcontrolled.com/repository.git
141- * [new branch] master -> master
190+ * [new branch] master -> master
142191~~~
143192
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+
145195~~~ bash
146196$ cctrlapp APP_NAME addon.add mysqls.free
147197$ cctrlapp APP_NAME deploy
148198~~~
149199
200+ ## Migrating the database
201+
150202Finally, 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):
152204
153205~~~ bash
154206$ cctrlapp APP_NAME run " python manage.py syncdb"
0 commit comments