summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-08 18:54:57 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-06-08 18:54:57 +0200
commitde3bf64db15b3925af72b7a2a502a37e2913e5c6 (patch)
treeba617c2f46f9b950cfa5236d9055e9c6e531763e /archaeological_finds
parent075994a01546a5ef47391d1a39c0802371e963d1 (diff)
downloadIshtar-de3bf64db15b3925af72b7a2a502a37e2913e5c6.tar.bz2
Ishtar-de3bf64db15b3925af72b7a2a502a37e2913e5c6.zip
Allow to save a find if no operation is associated
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/models.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index b84b7614f..f527bf5d3 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -418,7 +418,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
base_finds = [bf.pk for bf in self.base_finds.all()]
if self.upstream_treatment and \
self.upstream_treatment.pk not in treatments:
- treatments.append((self.upstream_treatment.upstream.distinct(
+ treatments.append(
+ (self.upstream_treatment.upstream.distinct(
).order_by('label').all(), self.upstream_treatment))
for upstream in self.upstream_treatment.upstream.all():
if upstream.pk != self.pk and not [
@@ -436,8 +437,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
base_finds = [bf.pk for bf in self.base_finds.all()]
if self.downstream_treatment and \
self.downstream_treatment.pk not in treatments:
- treatments.append((self.downstream_treatment.downstream.distinct(
- ).order_by('label').all(), self.downstream_treatment))
+ treatments.append(
+ (self.downstream_treatment.downstream.distinct(
+ ).order_by('label').all(), self.downstream_treatment))
for downstream in self.downstream_treatment.downstream.all():
if downstream.pk != self.pk and not [
bf.pk for bf in downstream.base_finds.all()
@@ -549,16 +551,18 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
if not self.index and q.count():
operation = q.order_by(
'-context_record__operation__start_date')\
- .all()[0].context_record.operation
- q = Find.objects\
- .filter(base_finds__context_record__operation=operation)
- if self.pk:
- q = q.exclude(pk=self.pk)
- if q.count():
- self.index = q.aggregate(Max('index'))['index__max'] + 1
- else:
- self.index = 1
- self.save()
+ .all()
+ if operation.count():
+ operation = operation.all()[0].context_record.operation
+ q = Find.objects\
+ .filter(base_finds__context_record__operation=operation)
+ if self.pk:
+ q = q.exclude(pk=self.pk)
+ if q.count():
+ self.index = q.aggregate(Max('index'))['index__max'] + 1
+ else:
+ self.index = 1
+ self.save()
for base_find in self.base_finds.all():
modified = False
if not base_find.index: