My form has first_name
and last_name
fields, but my model has just a name
field. In the clean()
method of the form I set self.cleaned_data['name']
, but when I try to save it I get this error:
<ul class="errorlist"><li>name<ul class="errorlist"><li>This field is required.</li开发者_JAVA百科></ul></li></ul>
If I exclude it,
class Meta:
model = UserProfile
exclude = ('name',)
however, then it doesn't get saved.
So how do I get it to both save, and not throw an error?
Adding
name = CharField(required=False)
To my form, but not displaying it on the page seems to work. I realized it was failing the first wave of validation before it even got to the clean()
method, which is why it erroring. Just had to set required=False
.
精彩评论