diff options
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r-- | archaeological_warehouse/forms.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 110f01c9b..050a62e7d 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -330,11 +330,16 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): container_type_id=cleaned_data.get("container_type"), parent_id=cleaned_data.get("parent") ) + pk = None if 'pk' in cleaned_data and cleaned_data['pk']: - q = q.exclude(pk=int(cleaned_data['pk'])) + pk = int(cleaned_data['pk']) + q = q.exclude(pk=pk) if q.count(): raise forms.ValidationError(_("This reference already exists for " "this warehouse.")) + if pk and pk == int(cleaned_data.get("parent")): + raise forms.ValidationError(_("A container cannot be a parent of " + "himself.")) return cleaned_data def save(self, user): @@ -643,6 +648,10 @@ class QAContainerFormMulti(QAForm): "qaparent"] new_tuples = [] for item in self.items: + if new_values.get("parent_id", None) and int( + new_values["parent_id"]) == item.pk: + raise forms.ValidationError( + _("A container cannot be a parent of himself.")) vals = { "container_type_id": item.container_type_id, "location_id": item.location_id, |