Django - Overriding cleaned_data
I have a form with fields that are not on the correspondent model. I use these "virtual" fields to fill a real one with the clean() method.
So, the user enters with data in the "virtual" field and I have to fill the real field with this same data.
I thought that overriding the cleaned_data["real_field"] would be possible, but I cannot do it.
My code is something like this:
(...)
cleaned_data['real_field'] = cleaned_dat开发者_开发问答a['virtual_field']
(...)
return cleaned_data
Any ideas on another way I can do it, or if I am doing it wrong, how do I fix it?
In your form class:
def clean(self):
cleaned_data = self.cleaned_data
cleaned_data['real_field'] = cleaned_data['virtual_field']
return cleaned_data
Nevermind, I had an error. The real field was not declared in the fieldsets (admin.py).
精彩评论