summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py45
1 files changed, 42 insertions, 3 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 39269ff87..64bae6769 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -54,26 +54,30 @@ from ishtar_common.models import (
Document,
DocumentItem,
document_attached_changed,
+ GeneralRecordRelations,
+ GeneralRelationType,
GeneralType,
GeoItem,
+ geo_item_pre_delete,
get_current_profile,
HierarchicalType,
HistoryModel,
Imported,
IshtarSiteProfile,
LightHistorizedItem,
+ main_item_pre_delete,
MainItem,
OrderedHierarchicalType,
OrderedType,
Organization,
OwnPerms,
Person,
+ post_delete_record_relation,
post_save_cache,
QuickAction,
+ RecordRelationManager,
SearchVectorConfig,
ValueGetter,
- main_item_pre_delete,
- geo_item_pre_delete
)
from ishtar_common.models_common import HistoricalRecords, SerializeItem, \
GeoVectorData, geodata_attached_changed
@@ -3944,10 +3948,45 @@ def base_find_find_changed(sender, **kwargs):
m2m_changed.connect(base_find_find_changed, sender=Find.base_finds.through)
-
m2m_changed.connect(document_attached_changed, sender=Find.documents.through)
+class FindRelationType(GeneralRelationType):
+ ADMIN_SECTION = _("Finds")
+ class Meta:
+ verbose_name = _("Find relation type")
+ verbose_name_plural = _("Find relation types")
+ ordering = ("order", "label")
+
+
+class FindRecordRelations(GeneralRecordRelations):
+ ADMIN_SECTION = _("Finds")
+ MAIN_ATTR = "left_record"
+ left_record = models.ForeignKey(
+ Find, related_name="right_relations", on_delete=models.CASCADE
+ )
+ right_record = models.ForeignKey(
+ Find, related_name="left_relations", on_delete=models.CASCADE
+ )
+ relation_type = models.ForeignKey(FindRelationType, on_delete=models.PROTECT)
+ objects = RecordRelationManager()
+
+ class Meta:
+ verbose_name = _("Find record relation")
+ verbose_name_plural = _("Find record relations")
+ ordering = (
+ "left_record__cached_label",
+ "relation_type",
+ "right_record__cached_label",
+ )
+ permissions = [
+ ("view_findrelation", "Can view all Find relations"),
+ ]
+
+
+post_delete.connect(post_delete_record_relation, sender=FindRecordRelations)
+
+
class FindDating(BaseDating):
SERIALIZE_EXCLUDE = ["find"]
CURRENT_MODEL = Find