diff --git a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js index 0d468d4b6df..86077ce38fa 100644 --- a/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js +++ b/django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js @@ -162,6 +162,24 @@ event.preventDefault(); opener.dismissRelatedLookupPopup(window, $(this).data("popup-opener")); }); + $('body').on('click', '.related-widget-wrapper-link', function(e) { + e.preventDefault(); + if (this.href) { + var event = $.Event('django:show-related', {href: this.href}); + $(this).trigger(event); + if (!event.isDefaultPrevented()) { + showRelatedObjectPopup(this); + } + } + }); + $('body').on('change', '.related-widget-wrapper select', function(e) { + var event = $.Event('django:update-related'); + $(this).trigger(event); + if (!event.isDefaultPrevented()) { + updateRelatedObjectLinks(this); + } + }); + $('.related-widget-wrapper select').trigger('change'); }); })(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 883376379f8..921635f8b90 100644 --- a/django/contrib/admin/static/admin/js/change_form.js +++ b/django/contrib/admin/static/admin/js/change_form.js @@ -20,24 +20,6 @@ showRelatedObjectLookupPopup(this); } }); - $('body').on('click', '.related-widget-wrapper-link', function(e) { - e.preventDefault(); - if (this.href) { - var event = $.Event('django:show-related', {href: this.href}); - $(this).trigger(event); - if (!event.isDefaultPrevented()) { - showRelatedObjectPopup(this); - } - } - }); - $('body').on('change', '.related-widget-wrapper select', function(e) { - var event = $.Event('django:update-related'); - $(this).trigger(event); - if (!event.isDefaultPrevented()) { - updateRelatedObjectLinks(this); - } - }); - $('.related-widget-wrapper select').trigger('change'); if (modelName) { $('form#' + modelName + '_form :input:visible:enabled:first').focus(); diff --git a/docs/releases/1.9.1.txt b/docs/releases/1.9.1.txt index 8180a2805f1..a40604780f0 100644 --- a/docs/releases/1.9.1.txt +++ b/docs/releases/1.9.1.txt @@ -61,3 +61,6 @@ Bugfixes * Fixed ``migrate --fake-initial`` detection of many-to-many tables (:ticket:`25922`). + +* Restored the functionality of the admin's ``list_editable`` add and change + buttons (:ticket:`25903`). diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 2db28c6f51e..5df79675a3f 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -87,8 +87,11 @@ class ChapterXtra1Admin(admin.ModelAdmin): class ArticleAdmin(admin.ModelAdmin): - list_display = ('content', 'date', callable_year, 'model_year', - 'modeladmin_year', 'model_year_reversed') + list_display = ( + 'content', 'date', callable_year, 'model_year', 'modeladmin_year', + 'model_year_reversed', 'section', + ) + list_editable = ('section',) list_filter = ('date', 'section') view_on_site = False fieldsets = ( diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 00e23302e14..c73164f3fc2 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4558,6 +4558,34 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): self.assertEqual(Pizza.objects.count(), 1) self.assertEqual(Topping.objects.count(), 2) + def test_list_editable_popups(self): + """ + list_editable foreign keys have add/change popups. + """ + s1 = Section.objects.create(name='Test section') + Article.objects.create( + content='

Middle content

', + date=datetime.datetime(2008, 3, 18, 11, 54, 58), + section=s1, + ) + self.admin_login(username='super', password='secret', login_url=reverse('admin:index')) + self.selenium.get(self.live_server_url + reverse('admin:admin_views_article_changelist')) + # Change popup + self.selenium.find_element_by_id('change_id_form-0-section').click() + self.wait_for_popup() + self.selenium.switch_to.window(self.selenium.window_handles[-1]) + self.wait_for_text('#content h1', 'Change section') + self.selenium.close() + self.selenium.switch_to.window(self.selenium.window_handles[0]) + + # Add popup + self.selenium.find_element_by_id('add_id_form-0-section').click() + self.wait_for_popup() + self.selenium.switch_to.window(self.selenium.window_handles[-1]) + self.wait_for_text('#content h1', 'Add section') + self.selenium.close() + self.selenium.switch_to.window(self.selenium.window_handles[0]) + class SeleniumAdminViewsChromeTests(SeleniumAdminViewsFirefoxTests): webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'