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.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index a0ba6c379..51a239230 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -431,6 +431,44 @@ class RecordRelations(GeneralRecordRelations, models.Model):
post_delete.connect(post_delete_record_relation, sender=RecordRelations)
+class RecordRelationView(models.Model):
+ """
+ CREATE VIEW record_relations AS
+ SELECT DISTINCT right_record_id as id,
+ right_record_id,
+ left_record_id,
+ relation_type_id
+ FROM archaeological_context_records_recordrelations;
+
+ -- deactivate deletion
+ CREATE RULE record_relations_del AS ON DELETE TO record_relations
+ DO INSTEAD DELETE FROM record_relations where id=NULL;
+ """
+ TABLE_COLS = [
+ "relation_type",
+ "right_record__label", "right_record__unit", "right_record__parcel",
+ "right_record__datings__period", "right_record__description"]
+ COL_LABELS = {
+ "relation_type": _(u"Relation type"),
+ "right_record__label": _(u"ID"),
+ "right_record__unit": _(u"Unit"),
+ "right_record__parcel": _(u"Parcel"),
+ "right_record__description": _(u"Description"),
+ "right_record__datings__period": _(u"Periods")
+ }
+ left_record = models.ForeignKey(ContextRecord, related_name='+')
+ right_record = models.ForeignKey(ContextRecord, related_name='+')
+ relation_type = models.ForeignKey(RelationType, related_name='+')
+
+ class Meta:
+ managed = False
+ db_table = 'record_relations'
+ unique_together = ('id', 'right_record')
+
+ def __unicode__(self):
+ return u"{} \"{}\"".format(self.relation_type, self.right_record)
+
+
class ContextRecordSource(Source):
SHOW_URL = 'show-contextrecordsource'
MODIFY_URL = 'record_source_modify'