Dimitris Kougioumtzis Blog About technology

Django inlineformset check for duplicates

Category Django

Posted on July 17, 2017



Django inlineformset check for duplicates


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class InlineFormSet(forms.BaseFormSet):
    def clean(self):
        if any(self.errors):
            return
        values = set()
        for form in self.forms:
            data = form.cleaned_data
            if data in values:
                raise forms.ValidationError(
                    'Duplicate values for "%s" are not allowed.' % data)
            values.add(data)

About

My name is Dimitris Kougioumtzis and i work as a Web developer at Rapidbounce Company

Elsewhere