diff options
| -rw-r--r-- | archaeological_warehouse/forms.py | 8 | ||||
| -rw-r--r-- | archaeological_warehouse/models.py | 5 | 
2 files changed, 6 insertions, 7 deletions
| diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 58d856844..94d37d092 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -318,14 +318,14 @@ class ContainerModifyForm(ContainerForm):          # manage unique ID          cleaned_data = super(ContainerModifyForm, self).clean()          index = cleaned_data.get("index", None) -        warehouse = cleaned_data.get("location") +        warehouse = cleaned_data.get("responsible")          if not index: -            q = models.Container.objects.filter(location__pk=warehouse) +            q = models.Container.objects.filter(responsible__pk=warehouse)              if not q.count():                  cleaned_data["index"] = 1              else: -                cleaned_data["index"] = q.all().aggregate( -                    Max("index"))["index__max"] + 1 +                cleaned_data["index"] = int(q.aggregate( +                    Max("index"))["index__max"]) + 1          else:              q = models.Container.objects.filter(                  index=index, location__pk=warehouse) diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index c9405fa37..31588cde2 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -819,10 +819,9 @@ class Container(DocumentItem, LightHistorizedItem, QRCodeItem, GeoItem,      def pre_save(self):          if not self.index and self.responsible_id: -            q = Container.objects.filter(responsible=self.responsible).order_by( -                '-index') +            q = Container.objects.filter(responsible=self.responsible)              if q.count(): -                self.index = q.all()[0].index + 1 +                self.index = int(q.aggregate(Max("index"))["index__max"]) + 1              else:                  self.index = 1 | 
