[Answered ]-How to preprocess values passed to CreateView

1๐Ÿ‘

I think you are on the right track in using the form to validate your data. However, your input is failing the validation test simply because the input data, formatted as a time value, is not the integer that your model requires.

You should use an unbound field in the form (or an unbound form) that accepts the data as entered โ€“ maybe as a character field. Then, use the clean method for this unbound field to confirm that the data can be converted (based on format and/or value). The actual conversion should happen in the view logic, perhaps in the form_valid() method.

๐Ÿ‘คDashdrum

1๐Ÿ‘

Laptime is a time and if you expect the user to enter it in the format โ€œ1:54.363โ€ the right field to use is TimeField

Validates that the given value is either a datetime.time or string
formatted in a particular time format

It seems that you are storing them in the database as microseconds. You would then need to check the form.is_valid() method and do the convertion either using the date time function or split and arithmatic.
.

๐Ÿ‘คe4c5

Leave a comment