|
@@ -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``
|
|
|
--------------------
|
|
|
|