View
def editor(request):
form = SessionForm(initial={
'end_time': datetime.datetime.now(),
})
if request.method == 'POST':
form = SessionForm(request.POST)
if form.is_valid():
form.save()
return render_to_response('planner/editor.html',
{'form': form}, context_instance=RequestContext(request),)
This view displays the form and re-displays it on error, so there are 2 cases:
- initialized
- on error
In the template, I’m trying to display the field end_time with a date filter
Test 1
<div>End value: {{ form.end_time.value }}</div>
<div>End value filtered: {{ form.end_time.value|date:"Y-m-d" }}</div>
Case 1 (initialized)
End value: 2012-04-23 12:30:00
End value filtered: 2012-04-23
Case 2 (on error)
End value: 2012-04-23 12:30:00
End value filtered:
Test 2
Now let’s try to remove the .value of end_time
<div>End value: {{ form.end_time.value }}</div>
<div>End value filtered: {{ form.end_time|date:"Y-m-d" }}</div>
Case 1 (initialized)
End value: 2012-04-23 12:30:00
End value filtered:
Case 2 (on error)
End value: 2012-04-23 12:30:00
End value filtered: 2012-04-23
As you can see it’s doing the inverse.
How can this be explained ?
Using
Instead of
Seems to works in both cases