Many to many field validation in django

Solution:

class MyForm(ModelForm):
    def clean(self):
        ok = False
        with transaction.atomic(savepoint=True, durable=False):
            ok = check(self.save(commit=True))
            transaction.set_rollback(True)
        if not ok:
            raise ValidationError(f'MyModel {self.instance.id} violates validation checks.')
        return super().clean()


@admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
    form = MyForm