when displaying a form for a new object, I'm trying to set a default
value for a date field using a filter in a template, like so:
<form action="." method="post">
{{ form.somefield|date:"Y-m-d" }}
This gives me an error:
'FormFieldWrapper' object has no attribute 'year'.
What am I doing wrong (I'm using generic views)?
The other solution for providing default values, that unfortunately
doesn't work either, is to set these in the view, when the request is
GET (again, generic views):
def limited_create_object(*args, **kwargs):
#...
if request.POST:
#
else:
new_data = request.GET.copy()
new_data[ 'somefield' ] = str( ...)
request._get = new_data
return create_object( *args, **kwargs)
The problem with this approach lies in create_update.py, line 56:
new_data = manipulator.flatten_data()
i.e. the data gets overwritten.
What am I missing? Any help would be greatly appreciated.
Regards,
Andres
The date filter only works on datetime.Date objects. form.somefield is
a FormFieldWrapper object that prints out the html for a form input
field, and is not a Date object.