diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 3a0ad74..e9c44c1 100644
a
|
b
|
class ModelAdmin(BaseModelAdmin):
|
967 | 967 | continue |
968 | 968 | if isinstance(f, models.ManyToManyField): |
969 | 969 | initial[k] = initial[k].split(",") |
| 970 | if isinstance(f, models.DateTimeField): |
| 971 | initial[k] = initial[k].split(",") |
970 | 972 | form = ModelForm(initial=initial) |
971 | 973 | prefixes = {} |
972 | 974 | for FormSet, inline in zip(self.get_formsets(request), inline_instances): |
diff --git a/docs/ref/contrib/admin/index.txt b/docs/ref/contrib/admin/index.txt
index 76ea780..d2707aa 100644
a
|
b
|
name, which can be anything you like. This argument becomes the prefix to the
|
1909 | 1909 | URL names for the purposes of :ref:`reversing them<admin-reverse-urls>`. This |
1910 | 1910 | is only necessary if you are using more than one ``AdminSite``. |
1911 | 1911 | |
| 1912 | Pre-populating fields in admin sites |
| 1913 | ------------------------------------ |
| 1914 | To pre-populate values for the fields of an admin site, simply append the |
| 1915 | value to the URL as GET parameters with the name of the field as key, e.g.:: |
| 1916 | |
| 1917 | /admin/model/add/?forename=John&surname=Doe |
| 1918 | |
| 1919 | Related fields can also be pre-populated:: |
| 1920 | |
| 1921 | /admin/modelname/add/?surname=Doe&relatedfieldvalue=2 |
| 1922 | |
1912 | 1923 | Adding views to admin sites |
1913 | 1924 | --------------------------- |
1914 | 1925 | |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 6037c2b..e580de8 100644
a
|
b
|
class AdminViewBasicTest(TestCase):
|
572 | 572 | self.client.get("/test_admin/admin/admin_views/inquisition/?leader__name=Palin&leader__age=27") |
573 | 573 | except SuspiciousOperation: |
574 | 574 | self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model") |
| 575 | |
| 576 | def test_field_prepopulation(self): |
| 577 | """ |
| 578 | Regression test for #9739 |
| 579 | Tests the prepopulation of fields within the admin site. |
| 580 | """ |
| 581 | # prepare some sections |
| 582 | section_0 = Section.objects.create(name='Section 1') |
| 583 | section_1 = Section.objects.create(name='Section 2') |
| 584 | section_2 = Section.objects.create(name='Section 3') |
| 585 | # call the addition page for articles |
| 586 | 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') |
| 587 | self.assertEqual(response.status_code, 200) |
| 588 | # test if the prepopulated values are within the response and in the correct fields |
| 589 | self.assertRegexpMatches(response.content, r'<input (?=.*name="title")(?=.*value="Testtitle").* />') |
| 590 | self.assertRegexpMatches(response.content, r'<textarea (?=.*name="content").*>Lorem Ipsum</textarea>') |
| 591 | self.assertRegexpMatches(response.content, r'<input (?=.*name="date_0")(?=.*value="2011-06-01").* />') |
| 592 | self.assertRegexpMatches(response.content, r'<input (?=.*name="date_1")(?=.*value="18:21:53").* />') |
| 593 | self.assertRegexpMatches(response.content, r'<option (?=.*value="2")(?=.*selected="selected").*>Section object</option>') |
| 594 | |
575 | 595 | |
576 | 596 | class AdminJavaScriptTest(AdminViewBasicTest): |
577 | 597 | urls = "regressiontests.admin_views.urls" |