summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/fields/__init__.py6
-rw-r--r--tests/model_fields/tests.py11
2 files changed, 9 insertions, 8 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 88c9ca9f28..fcea1597ef 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -542,11 +542,7 @@ class Field(RegisterLookupMixin):
return NotImplemented
def __hash__(self):
- return hash((
- self.creation_counter,
- self.model._meta.app_label if hasattr(self, 'model') else None,
- self.model._meta.model_name if hasattr(self, 'model') else None,
- ))
+ return hash(self.creation_counter)
def __deepcopy__(self, memodict):
# We don't have to deepcopy very much here, since most things are not
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py
index 5208b40dc9..86365989f0 100644
--- a/tests/model_fields/tests.py
+++ b/tests/model_fields/tests.py
@@ -128,9 +128,14 @@ class BasicFieldTests(SimpleTestCase):
self.assertLess(abstract_model_field, inherit2_model_field)
self.assertLess(inherit1_model_field, inherit2_model_field)
- self.assertNotEqual(hash(abstract_model_field), hash(inherit1_model_field))
- self.assertNotEqual(hash(abstract_model_field), hash(inherit2_model_field))
- self.assertNotEqual(hash(inherit1_model_field), hash(inherit2_model_field))
+ def test_hash_immutability(self):
+ field = models.IntegerField()
+ field_hash = hash(field)
+
+ class MyModel(models.Model):
+ rank = field
+
+ self.assertEqual(field_hash, hash(field))
class ChoicesTests(SimpleTestCase):