diff options
| -rw-r--r-- | archaeological_finds/models.py | 30 | 
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: | 
