# Best way to "pre-clean" a field before calling form.is\_valid()?

**URL:** <https://forum.djangoproject.com/t/best-way-to-pre-clean-a-field-before-calling-form-is-valid/32641>\
**Category:** Templates & Frontend\
**Created:** [July 2, 2024, 9:52pm UTC](https://forum.djangoproject.com/t/best-way-to-pre-clean-a-field-before-calling-form-is-valid/32641 "2024-07-02T21:52:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave/32/22371_2.png) [@dave](https://forum.djangoproject.com/u/dave)\
**Post date:** [July 2, 2024, 9:52pm UTC](https://forum.djangoproject.com/t/best-way-to-pre-clean-a-field-before-calling-form-is-valid/32641/1 "2024-07-02T21:52:43Z")

</div>

I’m using the AutoNumeric js library to format some of my input fields on my html page, for example, adding a % after a numeric value. The problem is that gets posted back as a string but the model is expecting an integer. So the normal clean\_\<field\_name\> method never gets called since it deals with Python objects (the integer).

So I guess I have two options: either clean the fields in the page before the post happens or in the view before I call form.is\_valid. Neither solution is pretty as I have several dozen fields. Do-able though, but are there any other options or is there something in Django that can handle this? I could change my model fields to be strings but I don’t want to do that, that would introduce all kinds of other issues.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 2, 2024, 9:58pm UTC](https://forum.djangoproject.com/t/best-way-to-pre-clean-a-field-before-calling-form-is-valid/32641/2 "2024-07-02T21:58:14Z")

</div>

Welcome @dave !

See [the `to_python` method](https://docs.djangoproject.com/en/5.0/ref/forms/validation/#form-and-field-validation) for form fields.

---

<div class="post-metadata">

**Author:** ![dave](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/dave/32/22371_2.png) [@dave](https://forum.djangoproject.com/u/dave)\
**Post date:** [July 2, 2024, 10:05pm UTC](https://forum.djangoproject.com/t/best-way-to-pre-clean-a-field-before-calling-form-is-valid/32641/3 "2024-07-02T22:05:55Z")

</div>

I’ll try that. Thanks!
