From 2fe12d70c4a11e2aabcda5fc9ec81578be90250d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 12 Sep 2019 19:13:54 +0200 Subject: Author: post merge duplicate authors on save - prevent duplicate in form validation --- ishtar_common/forms_common.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ishtar_common/forms_common.py') diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index dd55f95b4..486d25fcf 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -1425,6 +1425,15 @@ class AuthorForm(ManageOldType, NewItemForm): initial=self.init_data.get('author_type')) self.limit_fields() + def clean(self): + person_id = self.cleaned_data.get("person", None) + author_type_id = self.cleaned_data.get("author_type", None) + if not person_id or not author_type_id: + return self.cleaned_data + if models.Author.objects.filter(author_type_id=author_type_id, + person_id=person_id).count(): + raise forms.ValidationError(_("This author already exist.")) + def save(self, user): dct = self.cleaned_data dct['author_type'] = models.AuthorType.objects.get( -- cgit v1.2.3