diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-05 18:19:06 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-05 18:19:06 +0100 |
commit | 9f8f172e7e18c9d8fffc5d973f269a50a975d34e (patch) | |
tree | f7a78b7b5c988c1c98e588a97eaf1e313ac0d23f /archaeological_context_records/models.py | |
parent | 6830c1ba33771fdecca15aeffded5b92aa88775c (diff) | |
download | Ishtar-9f8f172e7e18c9d8fffc5d973f269a50a975d34e.tar.bz2 Ishtar-9f8f172e7e18c9d8fffc5d973f269a50a975d34e.zip |
Better management of context record relations tables (refs #3347)
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r-- | archaeological_context_records/models.py | 38 |
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' |