# forms.py changed data problem.

**URL:** <https://forum.djangoproject.com/t/forms-py-changed-data-problem/32909>\
**Category:** Forms & APIs\
**Created:** [July 12, 2024, 6:32am UTC](https://forum.djangoproject.com/t/forms-py-changed-data-problem/32909 "2024-07-12T06:32:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![white-seolpyo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/white-seolpyo/32/22386_2.png) [@white-seolpyo](https://forum.djangoproject.com/u/white-seolpyo)\
**Post date:** [July 12, 2024, 6:32am UTC](https://forum.djangoproject.com/t/forms-py-changed-data-problem/32909/1 "2024-07-12T06:32:19Z")

</div>

Using the html editor in Django’s forms.py always results in `has_changed() = True`.

I am using tinymce editor.

example

```auto
form django.forms import forms
from tinymce.widget import TinyMce

ex = '<p>asdf</p><p>\n</p><p>asdf</p>'
class a(forms.Form):
a = forms.Textarea(widget=TinyMce)

def clean_a(self):
 retrun ex
def __init__ (self, **kwargs):
 super(). __init__ (initial={'a': ex})

```

If you use this example code, then calling changed\_data always includes the a field.  
The reason is that the bound field data of a is as follows.

```auto
print(f"{self['a']="})
"self['a']=<p>asdf</p><p>\r\n</p><p>asdf</p>"

```

It may be unclear what the difference is, but you can see that the text `\n` to `\r\n` has been added.

Ironically, although initial and cleaned\_data match, it is recognized as a changed field because the data value of the bound field is different.

The process of confirming that data has been changed in the form appears to inherit multiple codes.

> <https://github.com/django/django/blob/main/django/forms/forms.py#L369>

> <https://github.com/django/django/blob/main/django/forms/forms.py#L161>

> <https://github.com/django/django/blob/main/django/forms/boundfield.py#L132>

In the middle, self[name] is called, and after checking it, I found out that it was a boundfield.

> <https://github.com/django/django/blob/main/django/forms/boundfield.py>

I wanna know.  
How to change bound data or,  
About how bound data is converted to HTML  
or other solution.

---

<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 12, 2024, 4:40pm UTC](https://forum.djangoproject.com/t/forms-py-changed-data-problem/32909/2 "2024-07-12T16:40:28Z")

</div>

If you create the field as a custom field subclass, you can edit the field in the `to_python` method of that field. This would allow you to alter the contents of the field coming in, before it is compared with the existing data. (For example, you could strip all the ‘linefeed’ characters from the incoming data.)

See [Form and field validation | Django documentation | Django](https://docs.djangoproject.com/en/5.0/ref/forms/validation/#form-and-field-validation) for details.
