﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9739	Admin does not correctly prefill DataTimeField from URL	gilhad	Fabian Binz	"I was not able to format URL for Admin interface to prefill DateTimeField with given value. 

It worked in 0.96, but does not work in 1.0 ( I used ../admin/MyApp/MyTable/add/?box=359&datum_date=2008-12-01&datum_time=17:30:27)


After some looking on source code and testing i find a solution:

- in /django/contrib/admin/options.py before line 520 add
{{{
  if isinstance(f, models.DateTimeField):
         initial[k] = initial[k].split("","")
}}}

- use this format: https://../admin/MyApp/MyTable/add/?box=359&datum=2008-12-01,17:30:27

For reference - the model of MyTable is such :
{{{
class MyTable(models.Model):
        box = models.ForeignKey(Boxes)
        datum =  models.DateTimeField(null=True, blank=True)
}}}
(plus some other insignificant fields. 
The ""datum"" field should be prefilled with some date, which is computed by long way (not simple now()) and the use must be able to edit it BEFORE saving it)

----

The problem arises from DateTimeField be treated by MultiWidget, but not properly broken when got by URL (GET)

-----

Patch:
{{{
--- options.py.old      2008-12-01 19:56:34.000000000 +0100
+++ options.py  2008-12-01 19:40:34.000000000 +0100
@@ -517,6 +517,8 @@
                     continue
                 if isinstance(f, models.ManyToManyField):
                     initial[k] = initial[k].split("","")
+                if isinstance(f, models.DateTimeField):
+                    initial[k] = initial[k].split("","")
             form = ModelForm(initial=initial)
             for FormSet in self.get_formsets(request):
                 formset = FormSet(instance=self.model())

}}}

"	Bug	assigned	contrib.admin	1.0	Normal			Sarah Boyce	Accepted	1	0	0	1	0	0
