summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py47
1 files changed, 32 insertions, 15 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index b51f33176..21b6d2b7c 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -36,15 +36,14 @@ from django.apps import apps
from ishtar_common.data_importer import post_importer_action, \
pre_importer_action
from ishtar_common.model_managers import ExternalIdManager, UUIDModelManager
-from ishtar_common.models import Document, GeneralType, get_external_id, \
- LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \
- DashboardFormItem, ShortMenuItem, Organization, OrganizationType, \
- document_attached_changed, SearchAltName, DynamicRequest, GeoItem, \
- QRCodeItem, SearchVectorConfig, DocumentItem, QuickAction, MainItem, \
- Merge
+from ishtar_common.models_common import GeneralType, \
+ LightHistorizedItem, OwnPerms, Address, post_save_cache, \
+ DashboardFormItem, document_attached_changed, SearchAltName, \
+ DynamicRequest, GeoItem, QRCodeItem, SearchVectorConfig, DocumentItem, \
+ QuickAction, MainItem, Merge
from ishtar_common.model_merging import merge_model_objects
from ishtar_common.utils import cached_label_changed, \
- cached_label_and_geo_changed
+ cached_label_and_geo_changed, get_external_id
class DivisionContainer(DashboardFormItem):
@@ -312,21 +311,24 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem,
warehouse_type = models.ForeignKey(WarehouseType,
verbose_name=_("Warehouse type"))
person_in_charge = models.ForeignKey(
- Person, on_delete=models.SET_NULL, related_name='warehouse_in_charge',
+ "ishtar_common.Person", on_delete=models.SET_NULL,
+ related_name='warehouse_in_charge',
verbose_name=_("Person in charge"), null=True, blank=True)
organization = models.ForeignKey(
- Organization, blank=True, null=True, related_name='warehouses',
- verbose_name=_("Organization"), on_delete=models.SET_NULL)
+ "ishtar_common.Organization", blank=True, null=True,
+ related_name='warehouses', verbose_name=_("Organization"),
+ on_delete=models.SET_NULL)
comment = models.TextField(_("Comment"), null=True, blank=True)
associated_divisions = models.ManyToManyField(
'WarehouseDivision', verbose_name=_("Divisions"), blank=True,
through='WarehouseDivisionLink'
)
documents = models.ManyToManyField(
- Document, related_name='warehouses', verbose_name=_("Documents"),
+ "ishtar_common.Document", related_name='warehouses',
+ verbose_name=_("Documents"),
blank=True)
main_image = models.ForeignKey(
- Document, related_name='main_image_warehouses',
+ "ishtar_common.Document", related_name='main_image_warehouses',
on_delete=models.SET_NULL,
verbose_name=_("Main image"), blank=True, null=True)
external_id = models.TextField(_("External ID"), blank=True, null=True)
@@ -372,6 +374,7 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem,
for k in Address.FIELDS:
dct_orga[k] = getattr(self, k)
+ OrganizationType = apps.get_model("ishtar_common", "OrganizationType")
q = OrganizationType.objects.filter(txt_idx="warehouse")
if q.count():
orga_type = q.all()[0]
@@ -382,6 +385,8 @@ class Warehouse(Address, DocumentItem, GeoItem, QRCodeItem,
)
dct_orga["organization_type"] = orga_type
dct_orga["name"] = self.name
+
+ Organization = apps.get_model("ishtar_common", "Organization")
orga = Organization.objects.create(**dct_orga)
orga.save() # force duplicates
self.organization = orga
@@ -862,10 +867,10 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem,
auto_external_id = models.BooleanField(
_("External ID is set automatically"), default=False)
documents = models.ManyToManyField(
- Document, related_name='containers', verbose_name=_("Documents"),
- blank=True)
+ "ishtar_common.Document", related_name='containers',
+ verbose_name=_("Documents"), blank=True)
main_image = models.ForeignKey(
- Document, related_name='main_image_containers',
+ "ishtar_common.Document", related_name='main_image_containers',
on_delete=models.SET_NULL,
verbose_name=_("Main image"), blank=True, null=True)
@@ -1040,6 +1045,18 @@ class Container(DocumentItem, Merge, LightHistorizedItem, QRCodeItem, GeoItem,
def get_town_polygons(self):
return self.location.get_town_polygons()
+ def contained_documents(self):
+ if not self.pk:
+ return
+ Document = apps.get_model("ishtar_common", "Document")
+ return Document.objects.filter(container_id=self.pk)
+
+ def contained_documents_ref(self):
+ if not self.pk:
+ return
+ Document = apps.get_model("ishtar_common", "Document")
+ return Document.objects.filter(container_ref_id=self.pk)
+
@property
def associated_filename(self):
filename = datetime.date.today().strftime('%Y-%m-%d')