Ticket #6500: 0055-Make-models-hashable.patch

File 0055-Make-models-hashable.patch, 853 bytes (added by Bastian Kleineidam <calvin@…>, 16 years ago)
  • django/db/models/base.py

    From 92501d8e41274d6ba4e803660c91ec6f634befaa Mon Sep 17 00:00:00 2001
    From: Bastian Kleineidam <calvin@debian.org>
    Date: Mon, 28 Jan 2008 13:58:32 +0100
    Subject: Make models hashable
    
    The Model instances should be hashable so that tests like
    "instance in set([instance1, instance2])" actually succeed.
    
    Signed-off-by: Bastian Kleineidam <calvin@debian.org>
    
    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 57660dd..c52d3dd 100644
    a b class Model(object):  
    110110    def __ne__(self, other):
    111111        return not self.__eq__(other)
    112112
     113    def __hash__ (self):
     114        return hash(self._get_pk_val())
     115
    113116    def __init__(self, *args, **kwargs):
    114117        dispatcher.send(signal=signals.pre_init, sender=self.__class__, args=args, kwargs=kwargs)
    115118
Back to Top