diff options
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r-- | ishtar_common/models.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 063a42522..a5fcc1a91 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -5904,6 +5904,27 @@ class Document( info.append(("rft.language", self.language.iso_code)) return '<span class="Z3988" title="{}">'.format(urlencode(info)) + def _set_container_by_code(self, code, target='container_id'): + Container = apps.get_model("archaeological_warehouse", "Container") + try: + container = Container.objects.get(code=code) + except DoesNotExist: + raise ImportError( + str(_("Container with code {} not found.")).format(code)) + except MultipleObjectsReturned: + raise ImportError( + str(_("Multiple containers with code {} found.")).format(code)) + self.__class__.objects.filter(pk=self.id).update( + **{target: container.pk}) + + @post_importer_action + def set_container_by_code(self, context, value): + return self._set_container_by_code(value) + + @post_importer_action + def set_container_ref_by_code(self, context, value): + return self._set_container_by_code(value, "container_ref_id") + def save(self, *args, **kwargs): no_path_change = "no_path_change" in kwargs and kwargs.pop("no_path_change") self.set_index() |