summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 04defbd81..a6aab9416 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -874,6 +874,15 @@ class GeneralRelationType(GeneralType):
return obj
+class RecordRelationManager(models.Manager):
+ def get_by_natural_key(self, left_record, right_record, relation_type):
+ return self.get(
+ left_record__uuid=left_record,
+ right_record__uuid=right_record,
+ relation_type__txt_idx=relation_type,
+ )
+
+
class GeneralRecordRelations(Imported):
class Meta:
abstract = True
@@ -882,8 +891,15 @@ class GeneralRecordRelations(Imported):
def general_types(cls):
return ["relation_type"]
+ def natural_key(self):
+ return (
+ self.left_record.uuid,
+ self.right_record.uuid,
+ self.relation_type.txt_idx,
+ )
+
def save(self, *args, **kwargs):
- super(GeneralRecordRelations, self).save(*args, **kwargs)
+ super().save(*args, **kwargs)
# after saving create the symmetric or the inverse relation