diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index fdc648060c..8b0af2b78d 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1083,7 +1083,7 @@ class ModelAdmin(BaseModelAdmin): attr = obj._meta.pk.attname value = obj.serializable_value(attr) popup_response_data = json.dumps({ - 'value': value, + 'value': six.text_type(value), 'obj': six.text_type(obj), }) return SimpleTemplateResponse('admin/popup_response.html', { diff --git a/tests/admin_views/models.py b/tests/admin_views/models.py index c105c42e4a..aa4476c9ed 100644 --- a/tests/admin_views/models.py +++ b/tests/admin_views/models.py @@ -16,6 +16,7 @@ from django.db import models from django.utils.encoding import python_2_unicode_compatible +@python_2_unicode_compatible class Section(models.Model): """ A simple section that links to articles, to test linking to related items @@ -23,6 +24,9 @@ class Section(models.Model): """ name = models.CharField(max_length=100) + def __str__(self): + return self.name + @property def name_property(self): """ diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 457ac47646..49afb860c5 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4481,8 +4481,10 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): """ list_editable foreign keys have add/change popups. """ + from selenium.webdriver.support.ui import Select s1 = Section.objects.create(name='Test section') Article.objects.create( + title='foo', content='

Middle content

', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=s1, @@ -4494,16 +4496,24 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): 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() + name_input = self.selenium.find_element_by_id('id_name') + name_input.clear() + name_input.send_keys('edited section') + self.selenium.find_element_by_xpath('//input[@value="Save"]').click() self.selenium.switch_to.window(self.selenium.window_handles[0]) + select = Select(self.selenium.find_element_by_id('id_form-0-section')) + self.assertEqual(select.first_selected_option.text, 'edited section') # 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.find_element_by_id('id_name').send_keys('new section') + self.selenium.find_element_by_xpath('//input[@value="Save"]').click() self.selenium.switch_to.window(self.selenium.window_handles[0]) + select = Select(self.selenium.find_element_by_id('id_form-0-section')) + self.assertEqual(select.first_selected_option.text, 'new section') class SeleniumAdminViewsChromeTests(SeleniumAdminViewsFirefoxTests):