diff options
| -rw-r--r-- | archaeological_finds/models_finds.py | 32 | ||||
| -rw-r--r-- | ishtar_common/models_common.py | 4 | 
2 files changed, 25 insertions, 11 deletions
| diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 2f73a55b8..97a408591 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -345,6 +345,13 @@ class BaseFind(BulkUpdatedItem, BaseHistorizedItem, GeoItem,      def natural_key(self):          return (self.uuid, ) +    def regenerate_external_id(self): +        self.skip_history_when_saving = True +        self._no_move = True +        self.external_id = "" +        self.auto_external_id = True +        self.save() +      @property      def operation(self):          return self.context_record.operation @@ -1766,19 +1773,26 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,          # images          return dct +    def regenerate_external_id(self): +        for bf in self.base_finds.all(): +            if self.base_finds.count() == 1: +                bf.label = self.label +            bf.regenerate_external_id() +        super(Find, self).regenerate_external_id() +      @property      def name(self): -        return " - ".join([base_find.name -                            for base_find in self.base_finds.all()]) +        return " - ".join(base_find.name for base_find in self.base_finds.all())      @property      def full_label(self): -        lbl = " - ".join([getattr(self, attr) -                           for attr in ( -                               'label', 'denomination', 'administrative_index') -                           if getattr(self, attr)]) -        base = " - ".join([base_find.complete_id() -                            for base_find in self.base_finds.all()]) +        lbl = " - ".join( +            getattr(self, attr) for attr in ( +                'label', 'denomination', 'administrative_index') +            if getattr(self, attr)) +        base = " - ".join( +            base_find.complete_id() for base_find in self.base_finds.all() +        )          if base:              lbl += ' ({})'.format(base)          return lbl @@ -1797,7 +1811,7 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem,          if no_base_finds:              return values          # by default attach first basefind data -        if not filtr or (filtr and prefix + "base_finds" not in filtr): +        if not filtr or prefix + "base_finds" not in filtr:              bf = self.get_first_base_find()              if not bf:                  return values diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py index 17ba88419..0afe9da9e 100644 --- a/ishtar_common/models_common.py +++ b/ishtar_common/models_common.py @@ -2879,8 +2879,8 @@ class MainItem(ShortMenuItem):              return          self.skip_history_when_saving = True          self._no_move = True -        if hasattr(self, "auto_external_id"): -            self.external_id = None +        self.external_id = "" +        self.auto_external_id = True          self.save()      def get_extra_actions(self, request): | 
