Ticket #8406: model-repr.diff
File model-repr.diff, 2.6 KB (added by , 16 years ago) |
---|
-
docs/db-api.txt
675 675 676 676 # This list contains a Blog object. 677 677 >>> Blog.objects.filter(name__startswith='Beatles') 678 [ Beatles Blog]678 [<Blog: Beatles Blog>] 679 679 680 680 # This list contains a dictionary. 681 681 >>> Blog.objects.filter(name__startswith='Beatles').values() … … 1247 1247 Example:: 1248 1248 1249 1249 >>> Blog.objects.in_bulk([1]) 1250 {1: Beatles Blog}1250 {1: <Blog: Beatles Blog>} 1251 1251 >>> Blog.objects.in_bulk([1, 2]) 1252 {1: Beatles Blog, 2: Cheddar Talk}1252 {1: <Blog: Beatles Blog>, 2: <Blog: Cheddar Talk>} 1253 1253 >>> Blog.objects.in_bulk([]) 1254 1254 {} 1255 1255 -
docs/overview.txt
74 74 75 75 # Now the new reporter is in the database. 76 76 >>> Reporter.objects.all() 77 [ John Smith]77 [<Reporter: John Smith>] 78 78 79 79 # Fields are represented as attributes on the Python object. 80 80 >>> r.full_name … … 82 82 83 83 # Django provides a rich database lookup API. 84 84 >>> Reporter.objects.get(id=1) 85 John Smith85 <Reporter: John Smith> 86 86 >>> Reporter.objects.get(full_name__startswith='John') 87 John Smith87 <Reporter: John Smith> 88 88 >>> Reporter.objects.get(full_name__contains='mith') 89 John Smith89 <Reporter: John Smith> 90 90 >>> Reporter.objects.get(id=2) 91 91 Traceback (most recent call last): 92 92 ... 93 DoesNotExist: Reporter does not exist for {'id__exact': 2}93 DoesNotExist: Reporter matching query does not exist. 94 94 95 95 # Create an article. 96 96 >>> from datetime import datetime … … 100 100 101 101 # Now the article is in the database. 102 102 >>> Article.objects.all() 103 [ Django is cool]103 [<Article: Django is cool>] 104 104 105 105 # Article objects get API access to related Reporter objects. 106 106 >>> r = a.reporter … … 109 109 110 110 # And vice versa: Reporter objects get API access to Article objects. 111 111 >>> r.article_set.all() 112 [ Django is cool]112 [<Article: Django is cool>] 113 113 114 114 # The API follows relationships as far as you need, performing efficient 115 115 # JOINs for you behind the scenes. 116 116 # This finds all articles by a reporter whose name starts with "John". 117 117 >>> Article.objects.filter(reporter__full_name__startswith="John") 118 [ Django is cool]118 [<Article: Django is cool>] 119 119 120 120 # Change an object by altering its attributes and calling save(). 121 121 >>> r.full_name = 'Billy Goat'