def unique_field_formset(field_name): from django.forms.models import BaseInlineFormSet class UniqueFieldFormSet (BaseInlineFormSet): def clean(self): if any(self.errors): # Don't bother validating the formset unless each form is valid on its own return values = set() for form in self.forms: value = form.cleaned_data[field_name] if value in values: raise forms.ValidationError('Duplicate values for "%s" are not allowed.' % field_name) values.add(value) return UniqueFieldFormSet