Doc'd that model instances with pk=None don't compare equal.
This commit is contained in:
parent
0a26f3c338
commit
224fe22bf1
|
@ -638,9 +638,10 @@ with :func:`~django.utils.encoding.python_2_unicode_compatible` as shown above.
|
||||||
.. method:: Model.__eq__()
|
.. method:: Model.__eq__()
|
||||||
|
|
||||||
The equality method is defined such that instances with the same primary
|
The equality method is defined such that instances with the same primary
|
||||||
key value and the same concrete class are considered equal. For proxy
|
key value and the same concrete class are considered equal, except that
|
||||||
models, concrete class is defined as the model's first non-proxy parent;
|
instances with a primary key value of ``None`` aren't equal to anything except
|
||||||
for all other models it is simply the model's class.
|
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::
|
For example::
|
||||||
|
|
||||||
|
@ -656,10 +657,18 @@ For example::
|
||||||
class MultitableInherited(MyModel):
|
class MultitableInherited(MyModel):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Primary keys compared
|
||||||
MyModel(id=1) == MyModel(id=1)
|
MyModel(id=1) == MyModel(id=1)
|
||||||
MyModel(id=1) == MyProxyModel(id=1)
|
|
||||||
MyModel(id=1) != MultitableInherited(id=1)
|
|
||||||
MyModel(id=1) != MyModel(id=2)
|
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)
|
||||||
|
|
||||||
``__hash__()``
|
``__hash__()``
|
||||||
--------------
|
--------------
|
||||||
|
|
Loading…
Reference in New Issue