from django.forms.models import BaseInlineFormSet
from django.core.exceptions import ValidationError


class ComponentInlineFormSet(BaseInlineFormSet):

    def clean(self):
        """Check that sum of components is 100%"""
if any(self.errors):
    return
total_sum = sum(form.cleaned_data['percentage'] for form in self.forms)
if total_sum != 100:
    raise ValidationError('Sum of components must be 100%')
Проверка встроенных строк перед сохранением модели