I was totally wrong to open this ticket, since
http://docs.python.org/ref/customization.html:
"""
If a class defines mutable objects and implements a __cmp__() or
__eq__() method, it should not implement __hash__()
"""
And django model is a mutable object. so we can't implement __hash__()
--~
see #2936, #2937
http://code.djangoproject.com/ticket/2936
http://code.djangoproject.com/ticket/2937
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to dj
On Thu, 2006-10-19 at 19:12 -0700, favo wrote:
> Since django Model has override __eq__ method, should override __hash__
> method too.
You are correct (since objects comparing equal should also hash to the
same value). Please file bug reports in the Trac so that they don't get
forgotten.
Thanks,
Since django Model has override __eq__ method, should override __hash__
method too.
{{{
def __eq__(self, other):
86 return isinstance(other, self.__class__) and
self._get_pk_val() == other._get_pk_val()
}}}
one possible implementation I think is,
{{{
def __hash__(self):
return ha