Refs #26524 -- Added a test for a <OneToOneField>_id reference in ModelAdmin.list_display.
This commit is contained in:
parent
e24c0a2d7c
commit
8b050cf9dc
|
@ -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').
|
||||
|
|
Loading…
Reference in New Issue