diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js index 282dfaed340..0f02051e6b5 100644 --- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js +++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js @@ -162,6 +162,14 @@ } }); $('.related-widget-wrapper select').trigger('change'); + $('.related-lookup').click(function(e) { + e.preventDefault(); + var event = $.Event('django:lookup-related'); + $(this).trigger(event); + if (!event.isDefaultPrevented()) { + showRelatedObjectLookupPopup(this); + } + }); }); })(django.jQuery); diff --git a/django/contrib/admin/static/admin/js/change_form.js b/django/contrib/admin/static/admin/js/change_form.js index 921635f8b90..994b52394e2 100644 --- a/django/contrib/admin/static/admin/js/change_form.js +++ b/django/contrib/admin/static/admin/js/change_form.js @@ -12,14 +12,6 @@ showAddAnotherPopup(this); } }); - $('.related-lookup').click(function(e) { - e.preventDefault(); - var event = $.Event('django:lookup-related'); - $(this).trigger(event); - if (!event.isDefaultPrevented()) { - showRelatedObjectLookupPopup(this); - } - }); if (modelName) { $('form#' + modelName + '_form :input:visible:enabled:first').focus(); diff --git a/docs/releases/1.8.12.txt b/docs/releases/1.8.12.txt index 0052a90b0d5..47581b3f191 100644 --- a/docs/releases/1.8.12.txt +++ b/docs/releases/1.8.12.txt @@ -15,3 +15,6 @@ Bugfixes * Fixed data loss on SQLite where ``DurationField`` values with fractional seconds could be saved as ``None`` (:ticket:`26324`). + +* Restored the functionality of the admin's ``raw_id_fields`` in + ``list_editable`` (:ticket:`26387`). diff --git a/docs/releases/1.9.5.txt b/docs/releases/1.9.5.txt index c88e92031f4..6f073c5c076 100644 --- a/docs/releases/1.9.5.txt +++ b/docs/releases/1.9.5.txt @@ -37,3 +37,6 @@ Bugfixes * Fixed a regression in ``CommonMiddleware`` that caused spurious warnings in logs on requests missing a trailing slash (:ticket:`26293`). + +* Restored the functionality of the admin's ``raw_id_fields`` in + ``list_editable`` (:ticket:`26387`). diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index bc2d08fc71c..a4ddde3af5f 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -1007,5 +1007,13 @@ site.register(Group, GroupAdmin) site2 = admin.AdminSite(name="namespaced_admin") site2.register(User, UserAdmin) site2.register(Group, GroupAdmin) +site2.register(ParentWithUUIDPK) +site2.register( + RelatedWithUUIDPKModel, + list_display=['pk', 'parent'], + list_editable=['parent'], + raw_id_fields=['parent'], +) + site7 = admin.AdminSite(name="admin7") site7.register(Article, ArticleAdmin2) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 356b1128da3..4802827a5c4 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4453,6 +4453,23 @@ class SeleniumTests(AdminSeleniumTestCase): self.assertEqual(select.first_selected_option.text, '---------') self.assertEqual(select.first_selected_option.get_attribute('value'), '') + def test_list_editable_raw_id_fields(self): + parent = ParentWithUUIDPK.objects.create(title='test') + parent2 = ParentWithUUIDPK.objects.create(title='test2') + RelatedWithUUIDPKModel.objects.create(parent=parent) + self.admin_login(username='super', password='secret', login_url=reverse('admin:index')) + change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_changelist', current_app=site2.name) + self.selenium.get(self.live_server_url + change_url) + self.selenium.find_element_by_id('lookup_id_form-0-parent').click() + self.wait_for_popup() + self.selenium.switch_to.window(self.selenium.window_handles[-1]) + # Select "parent2" in the popup. + self.selenium.find_element_by_link_text(str(parent2.pk)).click() + self.selenium.switch_to.window(self.selenium.window_handles[0]) + # The newly selected pk should appear in the raw id input. + value = self.selenium.find_element_by_id('id_form-0-parent').get_attribute('value') + self.assertEqual(value, str(parent2.pk)) + @override_settings(ROOT_URLCONF='admin_views.urls') class ReadonlyTest(AdminFieldExtractionMixin, TestCase):