From a501917d63927230ad836ddba937d870791f1812 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 8 Jun 2016 19:26:39 +0200 Subject: Allow to save a find if no operation is associated - 2 --- archaeological_finds/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py index f527bf5d3..adfa67394 100644 --- a/archaeological_finds/models.py +++ b/archaeological_finds/models.py @@ -549,9 +549,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): super(Find, self).save(*args, **kwargs) q = self.base_finds if not self.index and q.count(): - operation = q.order_by( - '-context_record__operation__start_date')\ - .all() + operation = q.filter( + context_record__operation__pk__isnull=False).order_by( + '-context_record__operation__start_date') if operation.count(): operation = operation.all()[0].context_record.operation q = Find.objects\ @@ -563,7 +563,8 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem): else: self.index = 1 self.save() - for base_find in self.base_finds.all(): + for base_find in self.base_finds.filter( + context_record__operation__pk__isnull=False).all(): modified = False if not base_find.index: modified = True -- cgit v1.2.3