Используя ответ Акайхолы, вот более полный пример:
Добавьте это к форме .py:
from django import forms
from django.forms.models import BaseInlineFormSet
class AtLeastOneRequiredInlineFormSet(BaseInlineFormSet):
def clean(self):
"""Check that at least one service has been entered."""
super(AtLeastOneRequiredInlineFormSet, self).clean()
if any(self.errors):
return
if not any(cleaned_data and not cleaned_data.get('DELETE', False)
for cleaned_data in self.cleaned_data):
raise forms.ValidationError('At least one item required.')
А потом, в вашем admin.py:
class DeskInline(admin.TabularInline):
model = Desk
formset = AtLeastOneRequiredInlineFormSet
class ChairAdmin(admin.ModelAdmin):
inlines = [DeskInline,]
admin.site.register(Chair, ChairAdmin)