<input type="hidden" name="date_posted" value="2007-02-19
09:36:22.531015" id="id_date_posted" />
but the corresponding field on the form does not accept all those
decimal places for the seconds in the time.
Is there an elegant way to fix this or do I just have to manually
clean up the time before I save the modified entry?
Thanks.
But the question is where. After you create the form class with
FormClass = forms.models.form_for_instance(anInstance)
. . .
form = FormClass(request.POST)
the form is bound to the data and it can't be changed, and
form.is_valid() will hit a validation error because the POST has the
datetime with all the decimal places.
So, the only place I can think of removing the decimals is after you
retrieve anInstance from the database, and before you used to create
the form class. And it seems a bad idea to have to modify the database
data for this purpose. It seems the problem arises when the form field
uses the strptime() method to parse and validate the input. There is
no way to specify a format string with decimals. My guess is that the
form_for_instance(anInstance) call should trim the decimals
automatically, so that the hidden field has the proper data without
intervention. However, this would also result in indirect database
modification. Perhaps the solution is to override the save() method in
the model and trim the decimals there.
Thanks,
I did not know enough earlier to understand your answer, but I do now.
Thanks.
Juan Pablo