Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added 'Comparing objects' section to docs/db-api.txt

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1986 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 017aa34ddb0e10f545c641097cd7de524f9f90e9 1 parent 946b1a5
@adrianholovaty adrianholovaty authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 docs/db-api.txt
View
19 docs/db-api.txt
@@ -509,6 +509,25 @@ deletes the object and has no return value. Example::
>>> c.delete()
+Comparing objects
+=================
+
+To compare two model objects, just use the standard Python comparison operator,
+the double equals sign: ``==``. Behind the scenes, that compares the primary
+key values of two models.
+
+Using the ``Poll`` example above, the following two statements are equivalent::
+
+ some_poll == other_poll
+ some_poll.id == other_poll.id
+
+If a model's primary key isn't called ID, no problem. Comparisons will always
+use the primary key, whatever it's called. For example, if a model's primary
+key field is called ``name``, these two statements are equivalent::
+
+ some_obj == other_obj
+ some_obj.name == other_obj.name
+
Extra instance methods
======================
Please sign in to comment.
Something went wrong with that request. Please try again.