Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>to_python</code> AFAIK is a method for fields, not forms. </p> <p><code>clean()</code> occurs after individual field cleaning, so your <code>ModelMultipleChoiceFields</code> <code>clean()</code> methods are raising validation errors and thus <code>cleaned_data</code> does not contain anything.</p> <p>You haven't provided examples for what kind of data is being input, but the answer lies in form field cleaning.</p> <p><a href="http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-a-specific-field-attribute</a></p> <p>You need to write validation specific to that field that either returns the correct data in the format your field is expecting, or raises a <code>ValidationError</code> so your view can re-render the form with error messages.</p> <p><strong>update</strong>: You're probably missing the <code>ModelForm</code> <code>__init__</code> -- see if that fixes it.</p> <pre><code>class MovieModelForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(MovieModelForm, self).__init__(*args, **kwargs) self.fields["actors"].widget = Textarea() def clean_actors(self): data = self.cleaned_data.get('actors') # validate incoming data. Convert the raw incoming string # to a list of ids this field is expecting. # if invalid, raise forms.ValidationError("Error MSG") return data.split(',') # just an example if data was '1,3,4' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload