I want to create a link which opens the django admin add page of a model with some fields pre filled.
I checked that it is possible to add parameters to the GET dictionary of the add form, as in:
<a href='/admin/myapp/mymodel/add?name=John'>add new mymodel with name John</a>
(actually I get the url with {% url 'admin:myapp_mymodel_add' %} but this is just to be explicit).
Now this works fine with numerical values, text values and foreign keys. But what about DateTime fields? When I try to pass such a field (I tried many formats like for example "2014-05-09 10:10:00") I always get a "server error" complaining that:
'unicode' object has no attribute 'date'
in the line of code:
django/forms/widgets.py in decompress, line 902
def decompress(self, value):
if value:
value = to_current_timezone(value)
return [value.date(), value.time().replace(microsecond=0)] ...
return [None, None]
where the variable "value" has the value I'm passing on the URL...
Question 1. I would assume that server code should not raise an exception depending on values passed by the user... isn't this a bug in the django libraries?
Question 2. How can I solve my problem i.e. pass an initial datetime through GET parameters to the admin "add" page of a model?