mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Made Model.__eq__ consider proxy models equivalent
Fixed #11892, fixed #16458, fixed #14492.
This commit is contained in:
@@ -494,6 +494,40 @@ using ``__str__()`` like this::
|
||||
# first_name and last_name will be unicode strings.
|
||||
return force_bytes('%s %s' % (self.first_name, self.last_name))
|
||||
|
||||
``__eq__``
|
||||
----------
|
||||
|
||||
.. 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. The term
|
||||
concrete class means proxy model's first non-proxy parent or the class
|
||||
itself if it isn't a proxy class.
|
||||
|
||||
For example::
|
||||
|
||||
form django.db import models
|
||||
|
||||
class MyModel(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
|
||||
class MyProxyModel(MyModel):
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
class MultitableInherited(MyModel):
|
||||
pass
|
||||
|
||||
MyModel(id=1) == MyModel(id=1)
|
||||
MyModel(id=1) == MyProxyModel(id=1)
|
||||
MyModel(id=1) != MultitableInherited(id=1)
|
||||
MyModel(id=1) != MyModel(id=2)
|
||||
|
||||
.. versionchanged:: 1.7
|
||||
|
||||
In previous versions only instances of the exact same class and same
|
||||
primary key value were considered equal.
|
||||
|
||||
``get_absolute_url``
|
||||
--------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user