#9739: Admin does correctly prefill DataTimeField from URL (GET) + patch
----------------------------------+-----------------------------------------
 Reporter:  gilhad                |       Owner:  nobody    
   Status:  new                   |   Milestone:            
Component:  django.contrib.admin  |     Version:  1.0       
 Keywords:                        |       Stage:  Unreviewed
Has_patch:  1                     |  
----------------------------------+-----------------------------------------
 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())

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9739>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to