mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #19082 -- Enabled admin field pre-population for existing objects.
Thanks to msaelices and d1ffuz0r for the initial patch and tests.
This commit is contained in:
@@ -644,8 +644,8 @@ class MainPrepopulated(models.Model):
|
||||
max_length=20,
|
||||
choices=(('option one', 'Option One'),
|
||||
('option two', 'Option Two')))
|
||||
slug1 = models.SlugField()
|
||||
slug2 = models.SlugField()
|
||||
slug1 = models.SlugField(blank=True)
|
||||
slug2 = models.SlugField(blank=True)
|
||||
|
||||
class RelatedPrepopulated(models.Model):
|
||||
parent = models.ForeignKey(MainPrepopulated)
|
||||
|
||||
@@ -3438,6 +3438,50 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase):
|
||||
slug2='option-one-tabular-inline-ignored-characters',
|
||||
)
|
||||
|
||||
def test_populate_existing_object(self):
|
||||
"""
|
||||
Ensure that the prepopulation works for existing objects too, as long
|
||||
as the original field is empty.
|
||||
Refs #19082.
|
||||
"""
|
||||
# Slugs are empty to start with.
|
||||
item = MainPrepopulated.objects.create(
|
||||
name=' this is the mAin nÀMë',
|
||||
pubdate='2012-02-18',
|
||||
status='option two',
|
||||
slug1='',
|
||||
slug2='',
|
||||
)
|
||||
self.admin_login(username='super',
|
||||
password='secret',
|
||||
login_url='/test_admin/admin/')
|
||||
|
||||
object_url = '%s%s' % (
|
||||
self.live_server_url,
|
||||
'/test_admin/admin/admin_views/mainprepopulated/{}/'.format(item.id))
|
||||
|
||||
self.selenium.get(object_url)
|
||||
self.selenium.find_element_by_css_selector('#id_name').send_keys(' the best')
|
||||
|
||||
# The slugs got prepopulated since they were originally empty
|
||||
slug1 = self.selenium.find_element_by_css_selector('#id_slug1').get_attribute('value')
|
||||
slug2 = self.selenium.find_element_by_css_selector('#id_slug2').get_attribute('value')
|
||||
self.assertEqual(slug1, 'main-name-best-2012-02-18')
|
||||
self.assertEqual(slug2, 'option-two-main-name-best')
|
||||
|
||||
# Save the object
|
||||
self.selenium.find_element_by_xpath('//input[@value="Save"]').click()
|
||||
self.wait_page_loaded()
|
||||
|
||||
self.selenium.get(object_url)
|
||||
self.selenium.find_element_by_css_selector('#id_name').send_keys(' hello')
|
||||
|
||||
# The slugs got prepopulated didn't change since they were originally not empty
|
||||
slug1 = self.selenium.find_element_by_css_selector('#id_slug1').get_attribute('value')
|
||||
slug2 = self.selenium.find_element_by_css_selector('#id_slug2').get_attribute('value')
|
||||
self.assertEqual(slug1, 'main-name-best-2012-02-18')
|
||||
self.assertEqual(slug2, 'option-two-main-name-best')
|
||||
|
||||
def test_collapsible_fieldset(self):
|
||||
"""
|
||||
Test that the 'collapse' class in fieldsets definition allows to
|
||||
|
||||
Reference in New Issue
Block a user