ModelForm excluded field can still be updated
|Reported by:||jgoldberg||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
class Object(models.Model): field_a = models.CharField(max_length=255) field_b = models.CharField(max_length=255) class ObjectForm(ModelForm): field_a = forms.CharField(max_length=255) class Meta: model = Object exclude = ['field_a']
When you initialize ObjectForm with POST data that includes the *form* field_a, doing a save(commit=False) will return an Object with field_a containing the value from the POST data. This doesn't seem like expected behavior: since field_a is listed in the exclude list, the data should only go into cleaned_data['field_a'], and not the object. An easy fix, of course, is to not name your form-specific fields with the same names as your model fields. However, there are cases where I want to use ModelForm, but for a couple fields I want to do manual manipulation of the form data before I update my model object.