Ticket #17929: 17929.tutorial-attribute-choice_text.diff
File 17929.tutorial-attribute-choice_text.diff, 4.0 KB (added by , 13 years ago) |
---|
-
docs/intro/tutorial01.txt
355 355 356 356 class Choice(models.Model): 357 357 poll = models.ForeignKey(Poll) 358 choice = models.CharField(max_length=200)358 choice_text = models.CharField(max_length=200) 359 359 votes = models.IntegerField() 360 360 361 361 The code is straightforward. Each model is represented by a class that … … 447 447 CREATE TABLE "polls_choice" ( 448 448 "id" serial NOT NULL PRIMARY KEY, 449 449 "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, 451 451 "votes" integer NOT NULL 452 452 ); 453 453 COMMIT; … … 598 598 class Choice(models.Model): 599 599 # ... 600 600 def __unicode__(self): 601 return self.choice 601 return self.choice_text 602 602 603 603 It's important to add :meth:`~django.db.models.Model.__unicode__` methods to 604 604 your models, not only for your own sanity when dealing with the interactive … … 690 690 [] 691 691 692 692 # Create three choices. 693 >>> p.choice_set.create(choice ='Not much', votes=0)693 >>> p.choice_set.create(choice_text='Not much', votes=0) 694 694 <Choice: Not much> 695 >>> p.choice_set.create(choice ='The sky', votes=0)695 >>> p.choice_set.create(choice_text='The sky', votes=0) 696 696 <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) 698 698 699 699 # Choice objects have API access to their related Poll objects. 700 700 >>> c.poll … … 714 714 [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>] 715 715 716 716 # 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') 718 718 >>> c.delete() 719 719 720 720 For 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
399 399 <h1>{{ poll.question }}</h1> 400 400 <ul> 401 401 {% for choice in poll.choice_set.all %} 402 <li>{{ choice.choice }}</li>402 <li>{{ choice.choice_text }}</li> 403 403 {% endfor %} 404 404 </ul> 405 405 -
docs/intro/tutorial04.txt
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 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