I'm mostly guessing, but you can try defining a custom widget for the
field. I'm not sure how much of the behavior of datetime fields
depends on the javascript that gets slapped to them. So instead, maybe
you could override the field's to_python method to append/replace the
seconds as needed, or basically always setting them to 00. Now that I
think of it, this is probably the easiest solution.

Cheers,
AT

On 7/25/11, Brian <brian.mcg...@gmail.com> wrote:
> Hi,
>
> I have a form with a TimeField and I'd like it to only accept values
> in the form hh:mm, as opposed to hh:mm:ss.
>
> The form is a ModelForm and I've overridden the 'time' field with a
> TimeField where I've specified the input_formats as ['%H:%M']. This
> works fine when entering value for a new instance of the model, but
> when I edit an existing instance, the value that I entered as '12:30'
> is rendered as '12:30:00' and so the instance fails to save.
>
> Without much hope of success (and that proved wildly optimistic), I
> tried changing the rendering of the form as follows:
>  {% if field.label == "Time" %}
>      {{ field | time:"H:i" }}
>  {% else %}
>     {{ field }}
>  {%endif%}
> But that didn't work even a little bit.
>
> Do I need to subclass TimeField? Is there a method that controls the
> "output_formats"?
> Or maybe that's not the way to do it. Could anyone offer any advice?
>
> Thanks in advance,
>
> Brian
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
Sent from my mobile device

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to