diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-09-12 19:13:00 -0700 |
|---|---|---|
| committer | Jon Dufresne <jon.dufresne@gmail.com> | 2016-09-12 19:20:35 -0700 |
| commit | 8b050cf9dcad3db39cc9ef44906bfc39f5aa3d25 (patch) | |
| tree | c69590bae9720c54e5aadf54f0fdf918a2df66c6 /tests/admin_views/tests.py | |
| parent | e24c0a2d7cab08c2fdcd3f873a3e85f70cd718b4 (diff) | |
Refs #26524 -- Added a test for a <OneToOneField>_id reference in ModelAdmin.list_display.
Diffstat (limited to 'tests/admin_views/tests.py')
| -rw-r--r-- | tests/admin_views/tests.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index ccc38920d0..fd8056513b 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -52,9 +52,9 @@ from .models import ( CyclicOne, CyclicTwo, DooHickey, Employee, EmptyModel, ExternalSubscriber, Fabric, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount, FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language, Link, - MainPrepopulated, ModelWithStringPrimaryKey, OtherStory, Paper, Parent, - ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona, Picture, - Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post, + MainPrepopulated, Media, ModelWithStringPrimaryKey, OtherStory, Paper, + Parent, ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona, + Picture, Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post, PrePopulatedPost, Promo, Question, Recommendation, Recommender, RelatedPrepopulated, RelatedWithUUIDPKModel, Report, Restaurant, RowLevelChangePermissionModel, SecretHideout, Section, ShortMessage, @@ -539,7 +539,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase): self.assertContentBefore(response, 'The First Item', 'The Middle Item') self.assertContentBefore(response, 'The Middle Item', 'The Last Item') - def test_has_related_field_in_list_display(self): + def test_has_related_field_in_list_display_fk(self): """Joins shouldn't be performed for <FK>_id fields in list display.""" state = State.objects.create(name='Karnataka') City.objects.create(state=state, name='Bangalore') @@ -551,6 +551,18 @@ class AdminViewBasicTest(AdminViewBasicTestCase): response.context['cl'].list_display = ['id', 'name', 'state_id'] self.assertIs(response.context['cl'].has_related_field_in_list_display(), False) + def test_has_related_field_in_list_display_o2o(self): + """Joins shouldn't be performed for <O2O>_id fields in list display.""" + media = Media.objects.create(name='Foo') + Vodcast.objects.create(media=media) + response = self.client.get(reverse('admin:admin_views_vodcast_changelist'), {}) + + response.context['cl'].list_display = ['media'] + self.assertIs(response.context['cl'].has_related_field_in_list_display(), True) + + response.context['cl'].list_display = ['media_id'] + self.assertIs(response.context['cl'].has_related_field_in_list_display(), False) + def test_limited_filter(self): """Ensure admin changelist filters do not contain objects excluded via limit_choices_to. This also tests relation-spanning filters (e.g. 'color__value'). |
