Ticket #17929: 17929.tutorial-choice-object-capitalized.diff

File 17929.tutorial-choice-object-capitalized.diff, 4.9 KB (added by rmattb, 13 years ago)
  • docs/intro/tutorial01.txt

     
    340340   the :ref:`DRY Principle <dry>`. The goal is to define your data model in one
    341341   place and automatically derive things from it.
    342342
    343 In our simple poll app, we'll create two models: polls and choices. A poll has
    344 a question and a publication date. A choice has two fields: the text of the
    345 choice and a vote tally. Each choice is associated with a poll.
     343In our simple poll app, we'll create two models: ``Poll`` and ``Choice``. A ``Poll`` has
     344a question and a publication date. A ``Choice`` has two fields: the text of the
     345choice and a vote tally. Each ``Choice`` is associated with a ``Poll``.
    346346
    347347These concepts are represented by simple Python classes. Edit the
    348348:file:`polls/models.py` file so it looks like this::
     
    385385schema, but in validation, as we'll soon see.
    386386
    387387Finally, note a relationship is defined, using
    388 :class:`~django.db.models.ForeignKey`. That tells Django each Choice is related
    389 to a single Poll. Django supports all the common database relationships:
     388:class:`~django.db.models.ForeignKey`. That tells Django each ``Choice`` is related
     389to a single ``Poll``. Django supports all the common database relationships:
    390390many-to-ones, many-to-manys and one-to-ones.
    391391
    392392.. _`Python path`: http://docs.python.org/tutorial/modules.html#the-module-search-path
     
    398398is able to:
    399399
    400400* Create a database schema (``CREATE TABLE`` statements) for this app.
    401 * Create a Python database-access API for accessing Poll and Choice objects.
     401* Create a Python database-access API for accessing ``Poll`` and ``Choice`` objects.
    402402
    403403But first we need to tell our project that the ``polls`` app is installed.
    404404
     
    679679    True
    680680
    681681    # Give the Poll a couple of Choices. The create call constructs a new
    682     # choice object, does the INSERT statement, adds the choice to the set
     682    # Choice object, does the INSERT statement, adds the choice to the set
    683683    # of available choices and returns the new Choice object. Django creates
    684684    # a set to hold the "other side" of a ForeignKey relation
    685685    # (e.g. a poll's choices) which can be accessed via the API.
  • docs/intro/tutorial02.txt

     
    276276dynamically add it as the selected choice on the "Add choice" form you're
    277277looking at.
    278278
    279 But, really, this is an inefficient way of adding Choice objects to the system.
     279But, really, this is an inefficient way of adding ``Choice`` objects to the system.
    280280It'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.
    282282
    283 Remove the ``register()`` call for the Choice model. Then, edit the ``Poll``
     283Remove the ``register()`` call for the ``Choice`` model. Then, edit the ``Poll``
    284284registration code to read::
    285285
    286286    class ChoiceInline(admin.StackedInline):
     
    296296
    297297    admin.site.register(Poll, PollAdmin)
    298298
    299 This tells Django: "Choice objects are edited on the Poll admin page. By
     299This tells Django: "``Choice`` objects are edited on the Poll admin page. By
    300300default, provide enough fields for 3 choices."
    301301
    302302Load the "Add poll" page to see how that looks, you may need to restart your development server:
     
    309309already-created object, you get another three extra slots.
    310310
    311311One 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
     312fields for entering related ``Choice`` objects. For that reason, Django offers a
    313313tabular way of displaying inline related objects; you just need to change
    314314the ``ChoiceInline`` declaration to read::
    315315
     
    397397fields as you'd like -- although because it uses a ``LIKE`` query behind the
    398398scenes, keep it reasonable, to keep your database happy.
    399399
    400 Finally, because Poll objects have dates, it'd be convenient to be able to
     400Finally, because ``Poll`` objects have dates, it'd be convenient to be able to
    401401drill down by date. Add this line::
    402402
    403403    date_hierarchy = 'pub_date'
  • docs/intro/tutorial03.txt

     
    411411
    412412Method-calling happens in the :ttag:`{% for %}<for>` loop:
    413413``poll.choice_set.all`` is interpreted as the Python code
    414 ``poll.choice_set.all()``, which returns an iterable of Choice objects and is
     414``poll.choice_set.all()``, which returns an iterable of ``Choice`` objects and is
    415415suitable for use in the :ttag:`{% for %}<for>` tag.
    416416
    417417See the :doc:`template guide </topics/templates>` for more about templates.
Back to Top