Ticket #17929: 17929.tutorial-attribute-choice_text.diff

File 17929.tutorial-attribute-choice_text.diff, 4.0 KB (added by rmattb, 3 years ago)
  • docs/intro/tutorial01.txt

     
    355355
    356356    class Choice(models.Model):
    357357        poll = models.ForeignKey(Poll)
    358         choice = models.CharField(max_length=200)
     358        choice_text = models.CharField(max_length=200)
    359359        votes = models.IntegerField()
    360360
    361361The code is straightforward. Each model is represented by a class that
     
    447447    CREATE TABLE "polls_choice" (
    448448        "id" serial NOT NULL PRIMARY KEY,
    449449        "poll_id" integer NOT NULL REFERENCES "polls_poll" ("id") DEFERRABLE INITIALLY DEFERRED,
    450         "choice" varchar(200) NOT NULL,
     450        "choice_text" varchar(200) NOT NULL,
    451451        "votes" integer NOT NULL
    452452    );
    453453    COMMIT;
     
    598598    class Choice(models.Model):
    599599        # ...
    600600        def __unicode__(self):
    601             return self.choice
     601            return self.choice_text
    602602
    603603It's important to add :meth:`~django.db.models.Model.__unicode__` methods to
    604604your models, not only for your own sanity when dealing with the interactive
     
    690690    []
    691691
    692692    # Create three choices.
    693     >>> p.choice_set.create(choice='Not much', votes=0)
     693    >>> p.choice_set.create(choice_text='Not much', votes=0)
    694694    <Choice: Not much>
    695     >>> p.choice_set.create(choice='The sky', votes=0)
     695    >>> p.choice_set.create(choice_text='The sky', votes=0)
    696696    <Choice: The sky>
    697     >>> c = p.choice_set.create(choice='Just hacking again', votes=0)
     697    >>> c = p.choice_set.create(choice_text='Just hacking again', votes=0)
    698698
    699699    # Choice objects have API access to their related Poll objects.
    700700    >>> c.poll
     
    714714    [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]
    715715
    716716    # Let's delete one of the choices. Use delete() for that.
    717     >>> c = p.choice_set.filter(choice__startswith='Just hacking')
     717    >>> c = p.choice_set.filter(choice_text__startswith='Just hacking')
    718718    >>> c.delete()
    719719
    720720For more information on model relations, see :doc:`Accessing related objects
  • docs/intro/tutorial03.txt

    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
    Cannot display: file marked as a binary type.
    svn:mime-type = application/octet-stream
     
    399399    <h1>{{ poll.question }}</h1>
    400400    <ul>
    401401    {% for choice in poll.choice_set.all %}
    402         <li>{{ choice.choice }}</li>
     402        <li>{{ choice.choice_text }}</li>
    403403    {% endfor %}
    404404    </ul>
    405405
  • docs/intro/tutorial04.txt

     
    2222    {% csrf_token %}
    2323    {% for choice in poll.choice_set.all %}
    2424        <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 />
    2626    {% endfor %}
    2727    <input type="submit" value="Vote" />
    2828    </form>
     
    168168
    169169    <ul>
    170170    {% 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>
    172172    {% endfor %}
    173173    </ul>
    174174
Back to Top