summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-03-30 15:05:00 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-03-30 15:05:00 +0200
commit1ee8d6d16836c25da4f75bcaf59d6e3f5b24a423 (patch)
tree38ff03cdcd7b07e4f951638054e8ca93dd4ffa10 /archaeological_warehouse/models.py
parent921174babfd04f1da248a4eb4536d882963b4700 (diff)
downloadIshtar-1ee8d6d16836c25da4f75bcaf59d6e3f5b24a423.tar.bz2
Ishtar-1ee8d6d16836c25da4f75bcaf59d6e3f5b24a423.zip
Container: fix index generation when only stationary containers are availables
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 7b694b799..5a852a367 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -1708,11 +1708,12 @@ class Container(
q = q.exclude(id=self.id)
if self.index and not q.count():
return
- q = Container.objects.filter(location=self.location)
- if q.count():
- self.index = int(q.all().aggregate(Max("index"))["index__max"]) + 1
- else:
- self.index = 1
+ q = Container.objects.filter(location=self.location, index__isnull=False)
+ self.index = (
+ int(q.all().aggregate(Max("index"))["index__max"]) + 1
+ if q.count()
+ else 1
+ )
if not self.cached_division:
self.cached_division = self._generate_cached_division()
@@ -1738,7 +1739,7 @@ class Container(
if not self.index and not self.container_type.stationary:
self.skip_history_when_saving = True
q = (
- Container.objects.filter(location=self.location)
+ Container.objects.filter(location=self.location, index__isnull=False)
.exclude(pk=self.pk)
.order_by("-index")
)