Filter "date" and FormFieldWrapper attribute error

3 views
Skip to first unread message

Andres Luga

unread,
Aug 26, 2006, 4:25:26 PM8/26/06
to django-users
Hi,

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

Gary Wilson

unread,
Aug 28, 2006, 1:35:04 AM8/28/06
to Django users
Andres Luga wrote:
> 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 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.

Reply all
Reply to author
Forward
0 new messages