Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17929 -- Improved tutorial wording and capitalization.

Thanks rmattb for the report and the patch.
  • Loading branch information...
commit 45284a90a515e71552f37c539a3cfdc38f15d869 1 parent ce8f874
Claude Paroz authored May 25, 2012
BIN  docs/intro/_images/admin10.png
BIN  docs/intro/_images/admin11.png
BIN  docs/intro/_images/admin11t.png
BIN  docs/intro/_images/admin12.png
29  docs/intro/tutorial01.txt
@@ -349,9 +349,10 @@ The first step in writing a database Web app in Django is to define your models
349 349
    the :ref:`DRY Principle <dry>`. The goal is to define your data model in one
350 350
    place and automatically derive things from it.
351 351
 
352  
-In our simple poll app, we'll create two models: polls and choices. A poll has
353  
-a question and a publication date. A choice has two fields: the text of the
354  
-choice and a vote tally. Each choice is associated with a poll.
  352
+In our simple poll app, we'll create two models: ``Poll`` and ``Choice``.
  353
+A ``Poll`` has a question and a publication date. A ``Choice`` has two fields:
  354
+the text of the choice and a vote tally. Each ``Choice`` is associated with a
  355
+``Poll``.
355 356
 
356 357
 These concepts are represented by simple Python classes. Edit the
357 358
 :file:`polls/models.py` file so it looks like this::
@@ -364,7 +365,7 @@ These concepts are represented by simple Python classes. Edit the
364 365
 
365 366
     class Choice(models.Model):
366 367
         poll = models.ForeignKey(Poll)
367  
-        choice = models.CharField(max_length=200)
  368
+        choice_text = models.CharField(max_length=200)
368 369
         votes = models.IntegerField()
369 370
 
370 371
 The code is straightforward. Each model is represented by a class that
@@ -394,8 +395,8 @@ Some :class:`~django.db.models.Field` classes have required elements.
394 395
 schema, but in validation, as we'll soon see.
395 396
 
396 397
 Finally, note a relationship is defined, using
397  
-:class:`~django.db.models.ForeignKey`. That tells Django each Choice is related
398  
-to a single Poll. Django supports all the common database relationships:
  398
+:class:`~django.db.models.ForeignKey`. That tells Django each ``Choice`` is related
  399
+to a single ``Poll``. Django supports all the common database relationships:
399 400
 many-to-ones, many-to-manys and one-to-ones.
400 401
 
401 402
 .. _`Python path`: http://docs.python.org/tutorial/modules.html#the-module-search-path
@@ -407,7 +408,7 @@ That small bit of model code gives Django a lot of information. With it, Django
407 408
 is able to:
408 409
 
409 410
 * Create a database schema (``CREATE TABLE`` statements) for this app.
410  
-* Create a Python database-access API for accessing Poll and Choice objects.
  411
+* Create a Python database-access API for accessing ``Poll`` and ``Choice`` objects.
411 412
 
412 413
 But first we need to tell our project that the ``polls`` app is installed.
413 414
 
@@ -456,7 +457,7 @@ statements for the polls app):
456 457
     CREATE TABLE "polls_choice" (
457 458
         "id" serial NOT NULL PRIMARY KEY,
458 459
         "poll_id" integer NOT NULL REFERENCES "polls_poll" ("id") DEFERRABLE INITIALLY DEFERRED,
459  
-        "choice" varchar(200) NOT NULL,
  460
+        "choice_text" varchar(200) NOT NULL,
460 461
         "votes" integer NOT NULL
461 462
     );
462 463
     COMMIT;
@@ -607,7 +608,7 @@ of this object. Let's fix that by editing the polls model (in the
607 608
     class Choice(models.Model):
608 609
         # ...
609 610
         def __unicode__(self):
610  
-            return self.choice
  611
+            return self.choice_text
611 612
 
612 613
 It's important to add :meth:`~django.db.models.Model.__unicode__` methods to
613 614
 your models, not only for your own sanity when dealing with the interactive
@@ -688,7 +689,7 @@ Save these changes and start a new Python interactive shell by running
688 689
     True
689 690
 
690 691
     # Give the Poll a couple of Choices. The create call constructs a new
691  
-    # choice object, does the INSERT statement, adds the choice to the set
  692
+    # Choice object, does the INSERT statement, adds the choice to the set
692 693
     # of available choices and returns the new Choice object. Django creates
693 694
     # a set to hold the "other side" of a ForeignKey relation
694 695
     # (e.g. a poll's choices) which can be accessed via the API.
@@ -699,11 +700,11 @@ Save these changes and start a new Python interactive shell by running
699 700
     []
700 701
 
701 702
     # Create three choices.
702  
-    >>> p.choice_set.create(choice='Not much', votes=0)
  703
+    >>> p.choice_set.create(choice_text='Not much', votes=0)
703 704
     <Choice: Not much>
704  
-    >>> p.choice_set.create(choice='The sky', votes=0)
  705
+    >>> p.choice_set.create(choice_text='The sky', votes=0)
705 706
     <Choice: The sky>
706  
-    >>> c = p.choice_set.create(choice='Just hacking again', votes=0)
  707
+    >>> c = p.choice_set.create(choice_text='Just hacking again', votes=0)
707 708
 
708 709
     # Choice objects have API access to their related Poll objects.
709 710
     >>> c.poll
@@ -723,7 +724,7 @@ Save these changes and start a new Python interactive shell by running
723 724
     [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]
724 725
 
725 726
     # Let's delete one of the choices. Use delete() for that.
726  
-    >>> c = p.choice_set.filter(choice__startswith='Just hacking')
  727
+    >>> c = p.choice_set.filter(choice_text__startswith='Just hacking')
727 728
     >>> c.delete()
728 729
 
729 730
 For more information on model relations, see :doc:`Accessing related objects
12  docs/intro/tutorial02.txt
@@ -276,11 +276,11 @@ in that window and click "Save," Django will save the poll to the database and
276 276
 dynamically add it as the selected choice on the "Add choice" form you're
277 277
 looking at.
278 278
 
279  
-But, really, this is an inefficient way of adding Choice objects to the system.
  279
+But, really, this is an inefficient way of adding ``Choice`` objects to the system.
280 280
 It'd be better if you could add a bunch of Choices directly when you create the
281  
-Poll object. Let's make that happen.
  281
+``Poll`` object. Let's make that happen.
282 282
 
283  
-Remove the ``register()`` call for the Choice model. Then, edit the ``Poll``
  283
+Remove the ``register()`` call for the ``Choice`` model. Then, edit the ``Poll``
284 284
 registration code to read::
285 285
 
286 286
     class ChoiceInline(admin.StackedInline):
@@ -296,7 +296,7 @@ registration code to read::
296 296
 
297 297
     admin.site.register(Poll, PollAdmin)
298 298
 
299  
-This tells Django: "Choice objects are edited on the Poll admin page. By
  299
+This tells Django: "``Choice`` objects are edited on the ``Poll`` admin page. By
300 300
 default, provide enough fields for 3 choices."
301 301
 
302 302
 Load the "Add poll" page to see how that looks, you may need to restart your development server:
@@ -309,7 +309,7 @@ by ``extra`` -- and each time you come back to the "Change" page for an
309 309
 already-created object, you get another three extra slots.
310 310
 
311 311
 One small problem, though. It takes a lot of screen space to display all the
312  
-fields for entering related Choice objects. For that reason, Django offers a
  312
+fields for entering related ``Choice`` objects. For that reason, Django offers a
313 313
 tabular way of displaying inline related objects; you just need to change
314 314
 the ``ChoiceInline`` declaration to read::
315 315
 
@@ -397,7 +397,7 @@ search terms, Django will search the ``question`` field. You can use as many
397 397
 fields as you'd like -- although because it uses a ``LIKE`` query behind the
398 398
 scenes, keep it reasonable, to keep your database happy.
399 399
 
400  
-Finally, because Poll objects have dates, it'd be convenient to be able to
  400
+Finally, because ``Poll`` objects have dates, it'd be convenient to be able to
401 401
 drill down by date. Add this line::
402 402
 
403 403
     date_hierarchy = 'pub_date'
4  docs/intro/tutorial03.txt
@@ -400,7 +400,7 @@ like:
400 400
     <h1>{{ poll.question }}</h1>
401 401
     <ul>
402 402
     {% for choice in poll.choice_set.all %}
403  
-        <li>{{ choice.choice }}</li>
  403
+        <li>{{ choice.choice_text }}</li>
404 404
     {% endfor %}
405 405
     </ul>
406 406
 
@@ -412,7 +412,7 @@ list-index lookup.
412 412
 
413 413
 Method-calling happens in the :ttag:`{% for %}<for>` loop:
414 414
 ``poll.choice_set.all`` is interpreted as the Python code
415  
-``poll.choice_set.all()``, which returns an iterable of Choice objects and is
  415
+``poll.choice_set.all()``, which returns an iterable of ``Choice`` objects and is
416 416
 suitable for use in the :ttag:`{% for %}<for>` tag.
417 417
 
418 418
 See the :doc:`template guide </topics/templates>` for more about templates.
4  docs/intro/tutorial04.txt
@@ -22,7 +22,7 @@ tutorial, so that the template contains an HTML ``<form>`` element:
22 22
     {% csrf_token %}
23 23
     {% for choice in poll.choice_set.all %}
24 24
         <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
25  
-        <label for="choice{{ forloop.counter }}">{{ choice.choice }}</label><br />
  25
+        <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
26 26
     {% endfor %}
27 27
     <input type="submit" value="Vote" />
28 28
     </form>
@@ -168,7 +168,7 @@ Now, create a ``results.html`` template:
168 168
 
169 169
     <ul>
170 170
     {% for choice in poll.choice_set.all %}
171  
-        <li>{{ choice.choice }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
  171
+        <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
172 172
     {% endfor %}
173 173
     </ul>
174 174
 

0 notes on commit 45284a9

Please sign in to comment.
Something went wrong with that request. Please try again.