summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 9a4fa7880..acc761a86 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -282,6 +282,24 @@ class RecordRelations(models.Model):
verbose_name = _(u"Record relation")
verbose_name_plural = _(u"Record relations")
+ def save(self, *args, **kwargs):
+ obj = super(RelationType, self).save(*args, **kwargs)
+
+ # after saving create the symetric or the inverse relation
+
+ sym_rel_type = obj.relation_type
+ if not obj.relation_type.symmetrical:
+ sym_rel_type = obj.relation_type.inverse_relation
+
+ # no symetric/inverse is defined
+ if not sym_rel_type:
+ return
+
+ dct = {'right_record':self.left_record, 'left_record':self.right_record,
+ 'relation_type':self.relation_type}
+ RecordRelations.objects.get_or_create(**dct)
+ return obj
+
class ContextRecordSource(Source):
class Meta:
verbose_name = _(u"Context record documentation")