summaryrefslogtreecommitdiff
path: root/tests/model_meta
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2014-07-14 14:23:34 +0300
committerTim Graham <timograham@gmail.com>2014-07-14 10:50:41 -0400
commit9cd5201abd24ba2632753029ee1957947cdc32f5 (patch)
tree4a005b8e63b7092202829f5dbc1627987fcd8c59 /tests/model_meta
parent38e001ab6caa8e5da68dbefd17322adcd2603c21 (diff)
downloaddjango-9cd5201abd24ba2632753029ee1957947cdc32f5.tar.gz
Fixed #22994 -- regression with generic FK + admin list_view
The reason for the regression was that the GenericForeignKey field isn't something meta.get_field_by_name() should return. The reason is that a couple of places in Django expects get_field_by_name() to work this way. It could make sense to return GFKs from get_field_by_name(), but that should likely be done as part of meta refactoring or virtual fields refactoring patches. Thanks to glicerinu@gmail.com for the report and to Tim for working on the issue.
Diffstat (limited to 'tests/model_meta')
-rw-r--r--tests/model_meta/test.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/tests/model_meta/test.py b/tests/model_meta/test.py
index 89a5575665..8fd0a6bb33 100644
--- a/tests/model_meta/test.py
+++ b/tests/model_meta/test.py
@@ -1,7 +1,7 @@
from django import test
-from django.db.models.fields import related, CharField, Field
-from django.contrib.contenttypes.fields import GenericForeignKey
+from django.db.models.fields import related, CharField, Field, FieldDoesNotExist
+from django.contrib.contenttypes.fields import GenericRelation
from .models import (
AbstractPerson, BasePerson, Person, Relating, Relation
@@ -650,7 +650,12 @@ class GetFieldByNameTests(OptionsBaseTests):
self.assertEqual(field_info[1:], (None, False, True))
self.assertIsInstance(field_info[0], related.RelatedObject)
- def test_get_virtual_field(self):
- field_info = Person._meta.get_field_by_name('content_object_base')
+ def test_get_generic_foreign_key(self):
+ # For historic reasons generic foreign keys aren't available.
+ with self.assertRaises(FieldDoesNotExist):
+ Person._meta.get_field_by_name('content_object_base')
+
+ def test_get_generic_relation(self):
+ field_info = Person._meta.get_field_by_name('generic_relation_base')
self.assertEqual(field_info[1:], (None, True, False))
- self.assertIsInstance(field_info[0], GenericForeignKey)
+ self.assertIsInstance(field_info[0], GenericRelation)