summaryrefslogtreecommitdiff
path: root/archaeological_context_records/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-05-28 11:31:04 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-06-17 13:21:28 +0200
commit764da8cb517be0224db8da4f881f569997146512 (patch)
treee19f1dfa26f4547001189721a89f0a5cbe036c57 /archaeological_context_records/models.py
parentdc2ecdd813af9a69fc95170c14b2a1acf8ecb111 (diff)
downloadIshtar-764da8cb517be0224db8da4f881f569997146512.tar.bz2
Ishtar-764da8cb517be0224db8da4f881f569997146512.zip
Fix cache generation for finds and context records
Diffstat (limited to 'archaeological_context_records/models.py')
-rw-r--r--archaeological_context_records/models.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py
index 1b63af51a..ace66aed6 100644
--- a/archaeological_context_records/models.py
+++ b/archaeological_context_records/models.py
@@ -293,7 +293,8 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
'cached_periods': _("Periods"),
'datings__period__label': _("Periods"),
'datings__period': _("Datings (period)"),
- 'detailled_related_context_records': _("Related context records"),
+ 'detailed_related_context_records': _("Related context records"),
+ "cached_related_context_records": _("Related context records"),
'operation__code_patriarche': _("Operation (Patriarche code)"),
'operation__common_name': _("Operation (name)"),
'parcel__external_id': _("Parcel (external ID)"),
@@ -302,10 +303,11 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
'parcel__year': _("Parcel (year)"),
'section__parcel_number': _("Parcel"),
'parcel__cached_label': _("Parcel"),
+ 'unit__label': _("Context record type"),
}
CONTEXTUAL_TABLE_COLS = {
'full': {
- 'related_context_records': 'detailled_related_context_records'
+ 'related_context_records': 'cached_related_context_records'
}
}
# statistics
@@ -427,7 +429,8 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
HISTORICAL_M2M = [
'datings', 'documentations'
]
- CACHED_LABELS = ['cached_label', 'cached_periods']
+ CACHED_LABELS = ['cached_label', 'cached_periods',
+ "cached_related_context_records"]
history = HistoricalRecords(bases=[HistoryModel])
objects = ExternalIdManager()
@@ -516,6 +519,10 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
_("Cached periods label"), blank=True, null=True,
help_text=_("Generated automatically - do not edit")
)
+ cached_related_context_records = models.TextField(
+ _("Cached related context records"), blank=True, null=True,
+ help_text=_("Generated automatically - do not edit")
+ )
class Meta:
verbose_name = _("Context Record")
@@ -716,6 +723,9 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
return " & ".join([dating.period.label
for dating in self.datings.all()])
+ def _generate_cached_related_context_records(self):
+ return self.detailed_related_context_records()
+
def _get_associated_cached_labels(self):
from archaeological_finds.models import Find, BaseFind
return list(Find.objects.filter(base_finds__context_record=self).all())\
@@ -793,12 +803,12 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,
q = q.filter(**fltr)
return q.count()
- def detailled_related_context_records(self):
+ def detailed_related_context_records(self):
crs = []
for cr in self.right_relations.all():
crs.append("{} ({})".format(cr.right_record,
cr.relation_type.get_tiny_label()))
- return " ; ".join(crs)
+ return " & ".join(crs)
def find_docs_q(self):
return Document.objects.filter(finds__base_finds__context_record=self)