I have a very simple Class Based View:
In views.py:
class IncidentEdit(UpdateView):
model=Incident
fields = visible_field_list
sucess_url = '/status'
works fine as-is. I have associated CreateView
, DeleteView
, etc. I can create edit and delete records. Now to fine-tune the project, I need to add field validation.
My question: Where do I put basic validation code when I have based the view on the 'model='
rather than 'form='
?
I could change everything to use form based views, but the whole idea was to keep it simple and it works, I just don't have the form validation except for basic 'Field Required' type validation that was defined in the model declaration.
For example, I need to make sure that one field equals the sum of two other fields. Like,
ClassRoomTotal = NumBoys + NumGirls
and raise a validation error
for the ClassRoomTotal
field if the sum doesn't match the total.
Thanks in advance.
I know it is a simple answer.
Suggestions like, "You can't do that, you have to use form=IncidentForm
and define a form class." would help.