from django.forms.util import ErrorList
from django import forms
class ContractUpdateView(UpdateView):
model = Contract
template_name = 'contract/contract_form.html'
form_class = ContractForm
def form_valid(self, form):
if self.request.POST.get('finish'):
if (
not form.cleaned_data['number'] or
not self.object.images.count()
):
form._errors[forms.forms.NON_FIELD_ERRORS] = ErrorList([
u'You have to add images and a contract number'
])
return self.form_invalid(form)
self.object.is_submitted = True
self.object = form.save()
return HttpResponseRedirect(self.get_success_url())