May be a simple question, but if I have a ModelForm:
class ExampleModelForm(forms.ModelForm):
class Meta:
exclude = ['username']
When I use the form, I want to inject a username I’ve got from elsewhere, but still want it to go through the validation process. If I use:
instance = ExampleModel(username='Foobar')
form = ExampleModelForm(request.POST, instance=instance)
if form.is_valid():
form.save()
Does the username ‘Foobar’ go through the same validation as the rest of the fields in the form?
Thanks,
J
No, the form doesn’t even contain the username field if it has been excluded.
If you want to perform validation on the field through the form, you should modify the POST dictionary.