So, I'm trying to validate some fields from an inlineformset_factory object, but I don't see how to do that in a clean way from this view (not using a Form class).
Would it be possible to override the .is_valid() method in this case?
Any help would be appreciated.
def tenant(request, id):
tenant = Tenant.objects.get(id=id)
DealerFormset = inlineformset_factory(Tenant, Dealer, fields=('name', 'phone_number'), extra=0)
formset = DealerFormset(instance=tenant)
if request.method == 'POST':
formset = DealerFormset(request.POST, instance=tenant)
if formset.is_valid(): # <--- How to add custom validations here?
formset.save()
return redirect('tenant_details', id=tenant.id)
context = {
'formset': formset,
}
return render(request, 'tenant_details.html', context)