Author: jacob
Date: 2008-08-29 11:09:29 -0500 (Fri, 29 Aug 2008)
New Revision: 8699
Modified:
django/trunk/django/contrib/admin/options.py
django/trunk/tests/regressiontests/admin_views/tests.py
Log:
Fixed #7738: support initial values via `GET` for `SelectMutliple` in the admin.
Modified: django/trunk/django/contrib/admin/options.py
===================================================================
--- django/trunk/django/contrib/admin/options.py 2008-08-29 16:07:19 UTC
(rev 8698)
+++ django/trunk/django/contrib/admin/options.py 2008-08-29 16:09:29 UTC
(rev 8699)
@@ -503,7 +503,17 @@
self.log_addition(request, new_object)
return self.response_add(request, new_object)
else:
- form = ModelForm(initial=dict(request.GET.items()))
+ # Prepare the dict of initial data from the request.
+ # We have to special-case M2Ms as a list of comma-separated PKs.
+ initial = dict(request.GET.items())
+ for k in initial:
+ try:
+ f = opts.get_field(k)
+ except FieldDoesNotExist:
+ pass
+ if isinstance(f, models.ManyToManyField):
+ initial[k] = initial[k].split(",")
+ form = ModelForm(initial=initial)
for FormSet in self.get_formsets(request):
formset = FormSet(instance=self.model())
formsets.append(formset)
Modified: django/trunk/tests/regressiontests/admin_views/tests.py
===================================================================
--- django/trunk/tests/regressiontests/admin_views/tests.py 2008-08-29
16:07:19 UTC (rev 8698)
+++ django/trunk/tests/regressiontests/admin_views/tests.py 2008-08-29
16:09:29 UTC (rev 8699)
@@ -36,6 +36,14 @@
response =
self.client.get('/test_admin/admin/admin_views/section/add/')
self.failUnlessEqual(response.status_code, 200)
+ def testAddWithGETArgs(self):
+ response =
self.client.get('/test_admin/admin/admin_views/section/add/', {'name': 'My
Section'})
+ self.failUnlessEqual(response.status_code, 200)
+ self.failUnless(
+ 'value="My Section"' in response.content,
+ "Couldn't find an input with the right value in the response."
+ )
+
def testBasicEditGet(self):
"""
A smoke test to ensureGET on the change_view works.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---