Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.x] Fixed #9508 -- Added an appropriate FileField.__hash__ implem…

…entation.

Required because we declare a custom __eq__ method.

Backport of r9997 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10000 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 055c01103de70b1f08321b1dbbcbc4da84821a79 1 parent 244bb7e
Malcolm Tredinnick authored March 08, 2009
4  django/db/models/fields/files.py
@@ -32,6 +32,10 @@ def __eq__(self, other):
32 32
     def __ne__(self, other):
33 33
         return not self.__eq__(other)
34 34
 
  35
+    def __hash__(self):
  36
+        # Required because we defined a custom __eq__.
  37
+        return hash(self.name)
  38
+
35 39
     # The standard File contains most of the necessary properties, but
36 40
     # FieldFiles can be instantiated without a name, so that needs to
37 41
     # be checked for here.
5  tests/regressiontests/file_storage/models.py
@@ -54,6 +54,11 @@ class Person(models.Model):
54 54
 >>> p.mugshot != p1.mugshot
55 55
 True
56 56
 
  57
+Bug #9508: Similarly to the previous test, make sure hash() works as expected
  58
+(equal items must hash to the same value).
  59
+>>> hash(p.mugshot) == hash(p2.mugshot)
  60
+True
  61
+
57 62
 # Bug #8175: correctly delete files that have been removed off the file system.
58 63
 >>> import os
59 64
 >>> p2 = Person(name="Fred")

0 notes on commit 055c011

Please sign in to comment.
Something went wrong with that request. Please try again.