I have a field in one of the models like :
field = models.CharField(max_length=10, null=True)
in admin.py I have
readonly_fields = ('field',)
When I try to save it from the admin, it does not throw a validation error which is quite sane.
But if I try to do this in my views.py
,
form = MyForm(#some data here from request.POST)
print form.is_valid()
I get error saying :
'this field is required'
Here MyForm
is a ModelForm
for that model. I am trying to create another form to replace the admin form so that my team can use the new form that I have created instead of the admin.
I want to run that form through ModelForm
that I have already written and I don't want to repeat code and re-write validation.
Why is this behavior different between admin form and any other form ?
Is saying blank=True
in my models the only way to make this work ?