Changeset 316
- Timestamp:
- 07/26/05 11:11:43 (3 years ago)
- Files:
-
- django/trunk/django/contrib/comments/models/comments.py (modified) (2 diffs)
- django/trunk/django/contrib/comments/templatetags/comments.py (modified) (4 diffs)
- django/trunk/django/contrib/comments/views/comments.py (modified) (3 diffs)
- django/trunk/django/contrib/comments/views/karma.py (modified) (2 diffs)
- django/trunk/django/contrib/comments/views/userflags.py (modified) (4 diffs)
- django/trunk/django/core/meta.py (modified) (1 diff)
- django/trunk/django/models/auth.py (modified) (2 diffs)
- django/trunk/django/models/core.py (modified) (1 diff)
- django/trunk/django/views/admin/doc.py (modified) (3 diffs)
- django/trunk/django/views/defaults.py (modified) (1 diff)
- django/trunk/docs/db-api.txt (modified) (1 diff)
- django/trunk/docs/overview.txt (modified) (2 diffs)
- django/trunk/docs/tutorial01.txt (modified) (6 diffs)
- django/trunk/docs/tutorial03.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/comments/models/comments.py
r292 r316 79 79 from django.core.exceptions import ObjectDoesNotExist 80 80 try: 81 return self.get_content_type().get_object_for_this_type( id__exact=self.object_id)81 return self.get_content_type().get_object_for_this_type(pk=self.object_id) 82 82 except ObjectDoesNotExist: 83 83 return None … … 194 194 from django.core.exceptions import ObjectDoesNotExist 195 195 try: 196 return self.get_content_type().get_object_for_this_type( id__exact=self.object_id)196 return self.get_content_type().get_object_for_this_type(pk=self.object_id) 197 197 except ObjectDoesNotExist: 198 198 return None django/trunk/django/contrib/comments/templatetags/comments.py
r292 r316 81 81 # because do_comment_form() validates hard-coded object IDs. 82 82 try: 83 self.content_type.get_object_for_this_type( id__exact=self.obj_id)83 self.content_type.get_object_for_this_type(pk=self.obj_id) 84 84 except ObjectDoesNotExist: 85 85 context['display_form'] = False … … 204 204 obj_id = tokens[3] 205 205 try: # ensure the object ID is valid 206 content_type.get_object_for_this_type( id__exact=obj_id)206 content_type.get_object_for_this_type(pk=obj_id) 207 207 except ObjectDoesNotExist: 208 208 raise template.TemplateSyntaxError, "'%s' tag refers to %s object with ID %s, which doesn't exist" % (self.tag_name, content_type.name, obj_id) … … 284 284 obj_id = tokens[3] 285 285 try: # ensure the object ID is valid 286 content_type.get_object_for_this_type( id__exact=obj_id)286 content_type.get_object_for_this_type(pk=obj_id) 287 287 except ObjectDoesNotExist: 288 288 raise template.TemplateSyntaxError, "'%s' tag refers to %s object with ID %s, which doesn't exist" % (self.tag_name, content_type.name, obj_id) … … 339 339 obj_id = tokens[3] 340 340 try: # ensure the object ID is valid 341 content_type.get_object_for_this_type( id__exact=obj_id)341 content_type.get_object_for_this_type(pk=obj_id) 342 342 except ObjectDoesNotExist: 343 343 raise template.TemplateSyntaxError, "'%s' tag refers to %s object with ID %s, which doesn't exist" % (self.tag_name, content_type.name, obj_id) django/trunk/django/contrib/comments/views/comments.py
r57 r316 198 198 content_type_id, object_id = target.split(':') # target is something like '52:5157' 199 199 try: 200 obj = contenttypes.get_object( id__exact=content_type_id).get_object_for_this_type(id__exact=object_id)200 obj = contenttypes.get_object(pk=content_type_id).get_object_for_this_type(pk=object_id) 201 201 except ObjectDoesNotExist: 202 202 raise Http404, "The comment form had an invalid 'target' parameter -- the object ID was invalid" … … 285 285 raise Http404, "Somebody tampered with the comment form (security violation)" 286 286 content_type_id, object_id = target.split(':') # target is something like '52:5157' 287 content_type = contenttypes.get_object( id__exact=content_type_id)287 content_type = contenttypes.get_object(pk=content_type_id) 288 288 try: 289 obj = content_type.get_object_for_this_type( id__exact=object_id)289 obj = content_type.get_object_for_this_type(pk=object_id) 290 290 except ObjectDoesNotExist: 291 291 raise Http404, "The comment form had an invalid 'target' parameter -- the object ID was invalid" … … 337 337 content_type_id, object_id = request.GET['c'].split(':') 338 338 try: 339 content_type = contenttypes.get_object( id__exact=content_type_id)340 obj = content_type.get_object_for_this_type( id__exact=object_id)339 content_type = contenttypes.get_object(pk=content_type_id) 340 obj = content_type.get_object_for_this_type(pk=object_id) 341 341 except ObjectDoesNotExist: 342 342 pass django/trunk/django/contrib/comments/views/karma.py
r57 r316 20 20 raise Http404, "Anonymous users cannot vote" 21 21 try: 22 comment = comments.get_object( id__exact=comment_id)22 comment = comments.get_object(pk=comment_id) 23 23 except comments.CommentDoesNotExist: 24 24 raise Http404, "Invalid comment ID" … … 27 27 karma.vote(request.user.id, comment_id, rating) 28 28 # Reload comment to ensure we have up to date karma count 29 comment = comments.get_object( id__exact=comment_id)29 comment = comments.get_object(pk=comment_id) 30 30 t = template_loader.get_template('comments/karma_vote_accepted') 31 31 c = Context(request, { django/trunk/django/contrib/comments/views/userflags.py
r57 r316 17 17 """ 18 18 try: 19 comment = comments.get_object( id__exact=comment_id, site_id__exact=SITE_ID)19 comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID) 20 20 except comments.CommentDoesNotExist: 21 21 raise Http404 … … 32 32 def flag_done(request, comment_id): 33 33 try: 34 comment = comments.get_object( id__exact=comment_id, site_id__exact=SITE_ID)34 comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID) 35 35 except comments.CommentDoesNotExist: 36 36 raise Http404 … … 51 51 """ 52 52 try: 53 comment = comments.get_object( id__exact=comment_id, site_id__exact=SITE_ID)53 comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID) 54 54 except comments.CommentDoesNotExist: 55 55 raise Http404 … … 73 73 def delete_done(request, comment_id): 74 74 try: 75 comment = comments.get_object( id__exact=comment_id, site_id__exact=SITE_ID)75 comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID) 76 76 except comments.CommentDoesNotExist: 77 77 raise Http404 django/trunk/django/core/meta.py
r311 r316 1147 1147 continue 1148 1148 lookup_list = kwarg.split(LOOKUP_SEPARATOR) 1149 # pk="value" is shorthand for (primary key)__exact="value" 1150 if lookup_list[-1] == 'pk': 1151 lookup_list = lookup_list[:-1] + [opts.pk.name, 'exact'] 1149 1152 if len(lookup_list) == 1: 1150 1153 _throw_bad_kwarg_error(kwarg) django/trunk/django/models/auth.py
r292 r316 223 223 from django.models.auth import users 224 224 from django.conf.settings import REGISTRATION_COOKIE_DOMAIN 225 user = users.get_object( id__exact=user_id)225 user = users.get_object(pk=user_id) 226 226 user.last_login = datetime.datetime.now() 227 227 user.save() … … 275 275 def get_edited_object(self): 276 276 "Returns the edited object represented by this log entry" 277 return self.get_content_type().get_object_for_this_type( id__exact=self.object_id)277 return self.get_content_type().get_object_for_this_type(pk=self.object_id) 278 278 279 279 def get_admin_url(self): django/trunk/django/models/core.py
r292 r316 15 15 "Returns the current site, according to the SITE_ID constant." 16 16 from django.conf.settings import SITE_ID 17 return get_object( id__exact=SITE_ID)17 return get_object(pk=SITE_ID) 18 18 19 19 class Package(meta.Model): django/trunk/django/views/admin/doc.py
r182 r316 1 import os2 import re3 import inspect4 1 from django.core import meta 5 2 from django import templatetags … … 15 12 except ImportError: 16 13 doc = None 14 import inspect, os, re 17 15 18 16 # Exclude methods starting with these strings from documentation … … 129 127 'title' : title, 130 128 'site_id': settings_mod.SITE_ID, 131 'site' : sites.get_object( id__exact=settings_mod.SITE_ID),129 'site' : sites.get_object(pk=settings_mod.SITE_ID), 132 130 'url' : simplify_regex(regex), 133 131 }) django/trunk/django/views/defaults.py
r233 r316 8 8 from django.models.core import contenttypes 9 9 try: 10 content_type = contenttypes.get_object( id__exact=content_type_id)11 obj = content_type.get_object_for_this_type( id__exact=object_id)10 content_type = contenttypes.get_object(pk=content_type_id) 11 obj = content_type.get_object_for_this_type(pk=object_id) 12 12 except ObjectDoesNotExist: 13 13 raise Http404, "Content type %s object %s doesn't exist" % (content_type_id, object_id) django/trunk/docs/db-api.txt
r299 r316 98 98 ...retrieves all polls published in January 2005 that have a question starting with "Would." 99 99 100 For convenience, there's a ``pk`` lookup type, which translates into 101 ``(primary_key)__exact``. In the polls example, these two statements are 102 equivalent:: 103 104 polls.get_object(id__exact=3) 105 polls.get_object(pk=3) 106 107 ``pk`` lookups also work across joins. In the polls example, these two 108 statements are equivalent:: 109 110 choices.get_list(poll__id__exact=3) 111 choices.get_list(poll__pk=3) 112 100 113 Ordering 101 114 ======== django/trunk/docs/overview.txt
r265 r316 94 94 django.models.news.ReporterDoesNotExist: Reporter does not exist for {'id__exact': 2} 95 95 96 # Lookup by a primary key is the most common case, so Django provides a 97 # shortcut for primary-key exact lookups. 98 # The following is identical to reporters.get_object(id__exact=1). 99 >>> reporters.get_object(pk=1) 100 John Smith 101 96 102 # Create an article. 97 103 >>> from datetime import datetime … … 201 207 # Use the Django API to find an object matching the URL criteria. 202 208 try: 203 a = articles.get_object(pub_date__year=year, pub_date__month=month, id__exact=article_id)209 a = articles.get_object(pub_date__year=year, pub_date__month=month, pk=article_id) 204 210 except articles.ArticleDoesNotExist: 205 211 raise Http404 django/trunk/docs/tutorial01.txt
r301 r316 50 50 module-level variables representing Django settings. Edit the file and change 51 51 these settings to match your database's connection parameters: 52 53 * ``DATABASE_ENGINE`` -- Either 'postgresql', 'mysql' or 'sqlite3'. 52 53 * ``DATABASE_ENGINE`` -- Either 'postgresql', 'mysql' or 'sqlite3'. 54 54 More coming soon. 55 * ``DATABASE_NAME`` -- The name of your database, or the full path to 55 * ``DATABASE_NAME`` -- The name of your database, or the full path to 56 56 the database file if using sqlite. 57 57 * ``DATABASE_USER`` -- Your database username (not used for sqlite). … … 135 135 136 136 .. admonition:: Philosophy 137 137 138 138 A model is the single, definitive source of data about your 139 139 data. It contains the essential fields and behaviors of the data you're … … 244 244 (polls) with a plural version of the object name (polls and choices). (You 245 245 can override this behavior.) 246 246 247 247 * Primary keys (IDs) are added automatically. (You can override this, too.) 248 248 249 249 * The foreign key relationship is made explicit by a ``REFERENCES`` statement. 250 250 251 251 * It's tailored to the database you're using, so database-specific field types 252 252 such as ``auto_increment`` (MySQL), ``serial`` (PostgreSQL), or ``integer … … 257 257 If you're interested, also run the following commands: 258 258 259 * ``django-admin.py sqlinitialdata polls`` -- Outputs the initial-data 259 * ``django-admin.py sqlinitialdata polls`` -- Outputs the initial-data 260 260 inserts required for Django's admin framework. 261 262 * ``django-admin.py sqlclear polls`` -- Outputs the necessary ``DROP 261 262 * ``django-admin.py sqlclear polls`` -- Outputs the necessary ``DROP 263 263 TABLE`` statements for this app, according to which tables already exist 264 264 in your database (if any). 265 265 266 266 * ``django-admin.py sqlindexes polls`` -- Outputs the ``CREATE INDEX`` 267 267 statements for this app. 268 268 269 269 * ``django-admin.py sqlall polls`` -- A combination of 'sql' and 270 270 'sqlinitialdata'. … … 373 373 [What's up] 374 374 375 # Lookup by a primary key is the most common case, so Django provides a 376 # shortcut for primary-key exact lookups. 377 # The following is identical to polls.get_object(id__exact=1). 378 >>> polls.get_object(pk=1) 379 What's up 380 375 381 # Make sure our custom method worked. 376 >>> p = polls.get_object( id__exact=1)382 >>> p = polls.get_object(pk=1) 377 383 >>> p.was_published_today() 378 384 False … … 380 386 # Give the Poll a couple of Choices. Each one of these method calls does an 381 387 # INSERT statement behind the scenes and returns the new Choice object. 382 >>> p = polls.get_object( id__exact=1)388 >>> p = polls.get_object(pk=1) 383 389 >>> p.add_choice(choice='Not much', votes=0) 384 390 Not much django/trunk/docs/tutorial03.txt
r299 r316 243 243 def detail(request, poll_id): 244 244 try: 245 p = polls.get_object( id__exact=poll_id)245 p = polls.get_object(pk=poll_id) 246 246 except polls.PollDoesNotExist: 247 247 raise Http404
