Ticket #5097: tutorial01.txt.diff
File tutorial01.txt.diff, 1.7 KB (added by , 17 years ago) |
---|
-
tutorial01.txt
461 461 >>> p.question 462 462 "What's up?" 463 463 >>> p.pub_date 464 datetime.datetime(200 5, 7, 15, 12, 00, 53)464 datetime.datetime(2007, 7, 15, 12, 00, 53) 465 465 466 466 # Change values by changing the attributes, then calling save(). 467 >>> p.pub_date = datetime(200 5, 4, 1, 0, 0)467 >>> p.pub_date = datetime(2007, 4, 1, 0, 0) 468 468 >>> p.save() 469 469 470 470 # objects.all() displays all the polls in the database. … … 537 537 >>> Poll.objects.filter(question__startswith='What') 538 538 [<Poll: What's up?>] 539 539 540 # Get the poll whose year is 200 5. Of course, if you're going through this540 # Get the poll whose year is 2007. Of course, if you're going through this 541 541 # tutorial in another year, change as appropriate. 542 >>> Poll.objects.get(pub_date__year=200 5)542 >>> Poll.objects.get(pub_date__year=2007) 543 543 <Poll: What's up?> 544 544 545 545 >>> Poll.objects.get(id=2) … … 580 580 581 581 # The API automatically follows relationships as far as you need. 582 582 # Use double underscores to separate relationships. 583 # This works as many levels deep as you want . There's no limit.584 # Find all Choices for any poll whose pub_date is in 200 5.585 >>> Choice.objects.filter(poll__pub_date__year=200 5)583 # This works as many levels deep as you want, there's no limit. 584 # Find all Choices for any poll whose pub_date is in 2007. 585 >>> Choice.objects.filter(poll__pub_date__year=2007) 586 586 [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>] 587 587 588 588 # Let's delete one of the choices. Use delete() for that.