Ticket #17929: 17929.tutorial-choice-object-capitalized.diff
File 17929.tutorial-choice-object-capitalized.diff, 4.9 KB (added by , 13 years ago) |
---|
-
docs/intro/tutorial01.txt
340 340 the :ref:`DRY Principle <dry>`. The goal is to define your data model in one 341 341 place and automatically derive things from it. 342 342 343 In our simple poll app, we'll create two models: polls and choices. A pollhas344 a question and a publication date. A choicehas two fields: the text of the345 choice and a vote tally. Each choice is associated with a poll.343 In our simple poll app, we'll create two models: ``Poll`` and ``Choice``. 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``. 346 346 347 347 These concepts are represented by simple Python classes. Edit the 348 348 :file:`polls/models.py` file so it looks like this:: … … 385 385 schema, but in validation, as we'll soon see. 386 386 387 387 Finally, note a relationship is defined, using 388 :class:`~django.db.models.ForeignKey`. That tells Django each Choiceis related389 to a single Poll. Django supports all the common database relationships: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: 390 390 many-to-ones, many-to-manys and one-to-ones. 391 391 392 392 .. _`Python path`: http://docs.python.org/tutorial/modules.html#the-module-search-path … … 398 398 is able to: 399 399 400 400 * Create a database schema (``CREATE TABLE`` statements) for this app. 401 * Create a Python database-access API for accessing Poll and Choiceobjects.401 * Create a Python database-access API for accessing ``Poll`` and ``Choice`` objects. 402 402 403 403 But first we need to tell our project that the ``polls`` app is installed. 404 404 … … 679 679 True 680 680 681 681 # 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 set682 # Choice object, does the INSERT statement, adds the choice to the set 683 683 # of available choices and returns the new Choice object. Django creates 684 684 # a set to hold the "other side" of a ForeignKey relation 685 685 # (e.g. a poll's choices) which can be accessed via the API. -
docs/intro/tutorial02.txt
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 Choiceobjects 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 Pollobject. Let's make that happen.281 ``Poll`` object. Let's make that happen. 282 282 283 Remove the ``register()`` call for the Choicemodel. 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 296 297 297 admin.site.register(Poll, PollAdmin) 298 298 299 This tells Django: " Choiceobjects are edited on the Poll admin page. By299 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 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 Choiceobjects. For that reason, Django offers a312 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 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 Pollobjects have dates, it'd be convenient to be able to400 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' -
docs/intro/tutorial03.txt
411 411 412 412 Method-calling happens in the :ttag:`{% for %}<for>` loop: 413 413 ``poll.choice_set.all`` is interpreted as the Python code 414 ``poll.choice_set.all()``, which returns an iterable of Choiceobjects and is414 ``poll.choice_set.all()``, which returns an iterable of ``Choice`` objects and is 415 415 suitable for use in the :ttag:`{% for %}<for>` tag. 416 416 417 417 See the :doc:`template guide </topics/templates>` for more about templates.