summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/instances.txt19
-rw-r--r--docs/releases/1.7.txt8
2 files changed, 27 insertions, 0 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
index 6295eb0407..da657a9a01 100644
--- a/docs/ref/models/instances.txt
+++ b/docs/ref/models/instances.txt
@@ -521,6 +521,25 @@ For example::
In previous versions only instances of the exact same class and same
primary key value were considered equal.
+``__hash__``
+------------
+
+.. method:: Model.__hash__()
+
+The ``__hash__`` method is based on the instance's primary key value. It
+is effectively hash(obj.pk). If the instance doesn't have a primary key
+value then a ``TypeError`` will be raised (otherwise the ``__hash__``
+method would return different values before and after the instance is
+saved, but changing the ``__hash__`` value of an instance `is forbidden
+in Python`_).
+
+.. versionchanged:: 1.7
+
+ In previous versions instance's without primary key value were
+ hashable.
+
+.. _is forbidden in Python: http://docs.python.org/reference/datamodel.html#object.__hash__
+
``get_absolute_url``
--------------------
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index 774d9d3161..6480a2505f 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -199,6 +199,14 @@ Miscellaneous
equal when primary keys match. Previously only instances of exact same
class were considered equal on primary key match.
+* The :meth:`django.db.models.Model.__eq__` method has changed such that
+ two ``Model`` instances without primary key values won't be considered
+ equal (unless they are the same instance).
+
+* The :meth:`django.db.models.Model.__hash__` will now raise ``TypeError``
+ when called on an instance without a primary key value. This is done to
+ avoid mutable ``__hash__`` values in containers.
+
Features deprecated in 1.7
==========================