summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/fields/files.py4
-rw-r--r--tests/regressiontests/file_storage/models.py5
2 files changed, 9 insertions, 0 deletions
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index f1c7468f48..1ea4415a18 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -32,6 +32,10 @@ class FieldFile(File):
def __ne__(self, other):
return not self.__eq__(other)
+ def __hash__(self):
+ # Required because we defined a custom __eq__.
+ return hash(self.name)
+
# The standard File contains most of the necessary properties, but
# FieldFiles can be instantiated without a name, so that needs to
# be checked for here.
diff --git a/tests/regressiontests/file_storage/models.py b/tests/regressiontests/file_storage/models.py
index 32fb83b348..099c25444e 100644
--- a/tests/regressiontests/file_storage/models.py
+++ b/tests/regressiontests/file_storage/models.py
@@ -54,6 +54,11 @@ False
>>> p.mugshot != p1.mugshot
True
+Bug #9508: Similarly to the previous test, make sure hash() works as expected
+(equal items must hash to the same value).
+>>> hash(p.mugshot) == hash(p2.mugshot)
+True
+
# Bug #8175: correctly delete files that have been removed off the file system.
>>> import os
>>> p2 = Person(name="Fred")