From 225b86ca211dd2fc022ed80a21a22371c6271d62 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 29 May 2018 13:26:18 +0200 Subject: Fix cached_label generation for finds --- archaeological_finds/models_finds.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 3e492222d..35dc6995a 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -1117,13 +1117,17 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel, return cls._return_get_owns(owns, values, get_short_menu_class) def _generate_cached_label(self): - return unicode(self) + self.cached_label_bulk_update(find_id=self.pk) + return Find.objects.filter(pk=self.pk).values( + 'cached_label')[0]['cached_label'] @classmethod - def cached_label_bulk_update(cls, operation_id=None, parcel_id=None, - context_record_id=None, transaction_id=None): + def cached_label_bulk_update( + cls, operation_id=None, parcel_id=None, context_record_id=None, + find_id=None, transaction_id=None): transaction_id, is_recursion = cls.bulk_recursion( - transaction_id, [operation_id, parcel_id, context_record_id]) + transaction_id, [operation_id, parcel_id, context_record_id, + find_id]) if is_recursion: return @@ -1155,9 +1159,13 @@ class Find(BulkUpdatedItem, ValueGetter, BaseHistorizedItem, ImageModel, ON myfbf.basefind_id = mybf.id AND mybf.context_record_id = %s """ args = [int(context_record_id)] + elif find_id: + filters = """ + where myf.id = %s + """ + args = [int(find_id)] else: return - sql = """ UPDATE "archaeological_finds_find" AS f SET cached_label = -- cgit v1.2.3