Ticket #9739: ticket9737.diff

File ticket9737.diff, 3.4 KB (added by Gandalfar, 3 years ago)

patch against r17364

  • django/contrib/admin/options.py

    diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
    index 3a0ad74..e9c44c1 100644
    a b class ModelAdmin(BaseModelAdmin): 
    967967                    continue
    968968                if isinstance(f, models.ManyToManyField):
    969969                    initial[k] = initial[k].split(",")
     970                if isinstance(f, models.DateTimeField):
     971                    initial[k] = initial[k].split(",")
    970972            form = ModelForm(initial=initial)
    971973            prefixes = {}
    972974            for FormSet, inline in zip(self.get_formsets(request), inline_instances):
  • docs/ref/contrib/admin/index.txt

    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 
    19091909URL names for the purposes of :ref:`reversing them<admin-reverse-urls>`. This
    19101910is only necessary if you are using more than one ``AdminSite``.
    19111911
     1912Pre-populating fields in admin sites
     1913------------------------------------
     1914To pre-populate values for the fields of an admin site, simply append the
     1915value 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   
     1919Related fields can also be pre-populated::
     1920
     1921    /admin/modelname/add/?surname=Doe&relatedfieldvalue=2
     1922
    19121923Adding views to admin sites
    19131924---------------------------
    19141925
  • tests/regressiontests/admin_views/tests.py

    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): 
    572572            self.client.get("/test_admin/admin/admin_views/inquisition/?leader__name=Palin&leader__age=27")
    573573        except SuspiciousOperation:
    574574            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&section=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       
    575595
    576596class AdminJavaScriptTest(AdminViewBasicTest):
    577597    urls = "regressiontests.admin_views.urls"
Back to Top