diff options
| author | Adam Chainz <adam@adamj.eu> | 2016-10-07 10:40:16 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-10-07 09:02:10 -0400 |
| commit | 27d352800c268856c7d69966bdfbdf6dc7a39da6 (patch) | |
| tree | 087dad4e4cc64c1e79460997c91c41413b972a8e | |
| parent | c2853807bc4899e0839877a75e0b487f4f7b72a9 (diff) | |
[1.10.x] Doc'd that model instances with pk=None don't compare equal.
Backport of 224fe22bf1628c1feff110ce993dcb33880bf3a3 from master
| -rw-r--r-- | docs/ref/models/instances.txt | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 49f7184279..e799d0078c 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -646,9 +646,10 @@ with :func:`~django.utils.encoding.python_2_unicode_compatible` as shown above. .. method:: Model.__eq__() The equality method is defined such that instances with the same primary -key value and the same concrete class are considered equal. For proxy -models, concrete class is defined as the model's first non-proxy parent; -for all other models it is simply the model's class. +key value and the same concrete class are considered equal, except that +instances with a primary key value of ``None`` aren't equal to anything except +themselves. For proxy models, concrete class is defined as the model's first +non-proxy parent; for all other models it's simply the model's class. For example:: @@ -664,10 +665,18 @@ For example:: class MultitableInherited(MyModel): pass + # Primary keys compared MyModel(id=1) == MyModel(id=1) + MyModel(id=1) != MyModel(id=2) + # Primay keys are None + MyModel(id=None) != MyModel(id=None) + # Same instance + instance = MyModel(id=None) + instance == instance + # Proxy model MyModel(id=1) == MyProxyModel(id=1) + # Multi-table inheritance MyModel(id=1) != MultitableInherited(id=1) - MyModel(id=1) != MyModel(id=2) ``__hash__()`` -------------- |
