Fixed #21431 -- GenRel->FK list_filter regression in admin
Report, analysis and tests from stephenmcd.
This commit is contained in:
parent
1116a5662c
commit
752d3d70da
|
@ -389,10 +389,8 @@ class NotRelationField(Exception):
|
||||||
|
|
||||||
|
|
||||||
def get_model_from_relation(field):
|
def get_model_from_relation(field):
|
||||||
if isinstance(field, models.related.RelatedObject):
|
if hasattr(field, 'get_path_info'):
|
||||||
return field.model
|
return field.get_path_info()[-1].to_opts.model
|
||||||
elif getattr(field, 'rel'): # or isinstance?
|
|
||||||
return field.rel.to
|
|
||||||
else:
|
else:
|
||||||
raise NotRelationField
|
raise NotRelationField
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
||||||
from django.contrib.admin.models import LogEntry, DELETION
|
from django.contrib.admin.models import LogEntry, DELETION
|
||||||
from django.contrib.admin.sites import LOGIN_FORM_KEY
|
from django.contrib.admin.sites import LOGIN_FORM_KEY
|
||||||
from django.contrib.admin.utils import quote
|
from django.contrib.admin.utils import quote
|
||||||
|
from django.contrib.admin.validation import ModelAdminValidator
|
||||||
from django.contrib.admin.views.main import IS_POPUP_VAR
|
from django.contrib.admin.views.main import IS_POPUP_VAR
|
||||||
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
|
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
|
||||||
from django.contrib.auth import REDIRECT_FIELD_NAME
|
from django.contrib.auth import REDIRECT_FIELD_NAME
|
||||||
|
@ -4682,3 +4683,20 @@ class InlineAdminViewOnSiteTest(TestCase):
|
||||||
self.assertContains(response,
|
self.assertContains(response,
|
||||||
'"/worker_inline/%s/%s/"' % (worker.surname, worker.name),
|
'"/worker_inline/%s/%s/"' % (worker.surname, worker.name),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AdminGenericRelationTests(TestCase):
|
||||||
|
def test_generic_relation_fk_list_filter(self):
|
||||||
|
"""
|
||||||
|
Validates a model with a generic relation to a model with
|
||||||
|
a foreign key can specify the generic+fk relationship
|
||||||
|
path as a list_filter. See trac #21428.
|
||||||
|
"""
|
||||||
|
class GenericFKAdmin(ModelAdmin):
|
||||||
|
list_filter = ('tags__content_type',)
|
||||||
|
|
||||||
|
validator = ModelAdminValidator()
|
||||||
|
try:
|
||||||
|
validator.validate_list_filter(GenericFKAdmin, Plot)
|
||||||
|
except ImproperlyConfigured:
|
||||||
|
self.fail("Couldn't validate a GenericRelation -> FK path in ModelAdmin.list_filter")
|
||||||
|
|
Loading…
Reference in New Issue