From 9a5545e4b6e467a99c1bca8c328f7bd76284ade9 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 3 Dec 2020 20:42:10 +0100 Subject: Fix container form with missing parents --- archaeological_warehouse/forms.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 5fcc105cd..42b8e1749 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -333,7 +333,8 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): dct['container_type'] = models.ContainerType.objects.get( pk=dct['container_type']) dct['location'] = models.Warehouse.objects.get(pk=dct['location']) - dct['parent'] = models.Container.objects.get(pk=dct['parent']) + if dct.get("parent", None): + dct['parent'] = models.Container.objects.get(pk=dct['parent']) new_item = models.Container(**dct) new_item.save() return new_item @@ -603,7 +604,7 @@ class QAContainerFormMulti(QAForm): def __init__(self, *args, **kwargs): self.items = kwargs["items"] super(QAContainerFormMulti, self).__init__(*args, **kwargs) - locations = set([item.location_id for item in self.items]) + locations = {item.location_id for item in self.items} if len(locations) == 1 and "qalocation" in self.fields: self.fields["qalocation"].initial = locations.pop() -- cgit v1.2.3