Ticket #8406: model-repr-r8629.diff
File model-repr-r8629.diff, 2.6 KB (added by , 16 years ago) |
---|
-
docs/intro/overview.txt
77 77 78 78 # Now the new reporter is in the database. 79 79 >>> Reporter.objects.all() 80 [ John Smith]80 [<Reporter: John Smith>] 81 81 82 82 # Fields are represented as attributes on the Python object. 83 83 >>> r.full_name … … 85 85 86 86 # Django provides a rich database lookup API. 87 87 >>> Reporter.objects.get(id=1) 88 John Smith88 <Reporter: John Smith> 89 89 >>> Reporter.objects.get(full_name__startswith='John') 90 John Smith90 <Reporter: John Smith> 91 91 >>> Reporter.objects.get(full_name__contains='mith') 92 John Smith92 <Reporter: John Smith> 93 93 >>> Reporter.objects.get(id=2) 94 94 Traceback (most recent call last): 95 95 ... 96 DoesNotExist: Reporter does not exist for {'id__exact': 2}96 DoesNotExist: Reporter matching query does not exist. 97 97 98 98 # Create an article. 99 99 >>> from datetime import datetime … … 103 103 104 104 # Now the article is in the database. 105 105 >>> Article.objects.all() 106 [ Django is cool]106 [<Article: Django is cool>] 107 107 108 108 # Article objects get API access to related Reporter objects. 109 109 >>> r = a.reporter … … 112 112 113 113 # And vice versa: Reporter objects get API access to Article objects. 114 114 >>> r.article_set.all() 115 [ Django is cool]115 [<Article: Django is cool>] 116 116 117 117 # The API follows relationships as far as you need, performing efficient 118 118 # JOINs for you behind the scenes. 119 119 # This finds all articles by a reporter whose name starts with "John". 120 120 >>> Article.objects.filter(reporter__full_name__startswith="John") 121 [ Django is cool]121 [<Article: Django is cool>] 122 122 123 123 # Change an object by altering its attributes and calling save(). 124 124 >>> r.full_name = 'Billy Goat' -
docs/ref/models/querysets.txt
190 190 191 191 # This list contains a Blog object. 192 192 >>> Blog.objects.filter(name__startswith='Beatles') 193 [ Beatles Blog]193 [<Blog: Beatles Blog>] 194 194 195 195 # This list contains a dictionary. 196 196 >>> Blog.objects.filter(name__startswith='Beatles').values() … … 650 650 Example:: 651 651 652 652 >>> Blog.objects.in_bulk([1]) 653 {1: Beatles Blog}653 {1: <Blog: Beatles Blog>} 654 654 >>> Blog.objects.in_bulk([1, 2]) 655 {1: Beatles Blog, 2: Cheddar Talk}655 {1: <Blog: Beatles Blog>, 2: <Blog: Cheddar Talk>} 656 656 >>> Blog.objects.in_bulk([]) 657 657 {} 658 658