Ticket #9739: 9739-r16345.diff
File 9739-r16345.diff, 3.4 KB (added by , 13 years ago) |
---|
-
docs/ref/contrib/admin/index.txt
1817 1817 URL names for the purposes of :ref:`reversing them<admin-reverse-urls>`. This 1818 1818 is only necessary if you are using more than one ``AdminSite``. 1819 1819 1820 Pre-populating fields in admin sites 1821 -------------------------------- 1822 It's easy to offer prefilled values for the fields of an admin site. 1823 Simply append the value to the URL as GET parameters with the name of the 1824 field as key, e.g.: 1825 1826 /admin/model/add/?forename=John&surname=Doe 1827 1828 Related fields can also be prefilled: 1829 1830 /admin/modelname/add/?surname=Doe&relatedfieldvalue=2 1831 1820 1832 Adding views to admin sites 1821 1833 --------------------------- 1822 1834 -
django/contrib/admin/options.py
911 911 continue 912 912 if isinstance(f, models.ManyToManyField): 913 913 initial[k] = initial[k].split(",") 914 if isinstance(f, models.DateTimeField): 915 initial[k] = initial[k].split(",") 914 916 form = ModelForm(initial=initial) 915 917 prefixes = {} 916 918 for FormSet, inline in zip(self.get_formsets(request), -
tests/regressiontests/admin_views/tests.py
535 535 self.client.get("/test_admin/admin/admin_views/inquisition/?leader__name=Palin&leader__age=27") 536 536 except SuspiciousOperation: 537 537 self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model") 538 539 def test_field_prepopulation(self): 540 """ 541 Regression test for #9739 542 Tests the prepopulation of fields within the admin site. 543 """ 544 # prepare some sections 545 section_0 = Section.objects.create(name='Section 1') 546 section_1 = Section.objects.create(name='Section 2') 547 section_2 = Section.objects.create(name='Section 3') 548 # call the addition page for articles 549 response = self.client.get('/test_admin/' + self.urlbit + '/admin_views/article/add/?title=Testtitle&content=Lorem%20Ipsum&date=2011-06-01,18:21:53§ion=2') 550 self.assertEqual(response.status_code, 200) 551 # test if the prepopulated values are within the response and in the correct fields 552 self.assertRegexpMatches(response.content, r'<input (?=.*name="title")(?=.*value="Testtitle").* />') 553 self.assertRegexpMatches(response.content, r'<textarea (?=.*name="content").*>Lorem Ipsum</textarea>') 554 self.assertRegexpMatches(response.content, r'<input (?=.*name="date_0")(?=.*value="2011-06-01").* />') 555 self.assertRegexpMatches(response.content, r'<input (?=.*name="date_1")(?=.*value="18:21:53").* />') 556 self.assertRegexpMatches(response.content, r'<option (?=.*value="2")(?=.*selected="selected").*>Section object</option>') 557 538 558 539 559 class AdminJavaScriptTest(AdminViewBasicTest): 540 560 def testSingleWidgetFirsFieldFocus(self):