diff options
Diffstat (limited to 'archaeological_context_records/models.py')
| -rw-r--r-- | archaeological_context_records/models.py | 18 | 
1 files changed, 15 insertions, 3 deletions
| diff --git a/archaeological_context_records/models.py b/archaeological_context_records/models.py index 3b5e24602..1b63af51a 100644 --- a/archaeological_context_records/models.py +++ b/archaeological_context_records/models.py @@ -283,12 +283,14 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,      EXTERNAL_ID_KEY = 'context_record_external_id'      EXTERNAL_ID_DEPENDENCIES = ['base_finds']      TABLE_COLS = ['label', 'operation__common_name', 'town__name', -                  'parcel__cached_label', 'unit'] +                  'parcel__cached_label', 'unit__label']      if settings.COUNTRY == 'fr':          TABLE_COLS.insert(1, 'operation__code_patriarche') -    TABLE_COLS_FOR_OPE = ['label', 'parcel', 'unit', -                          'datings__period__label', 'description'] +    TABLE_COLS_FOR_OPE = ['label', 'parcel', 'unit__label', +                          'cached_periods', 'description'] +    NEW_QUERY_ENGINE = True      COL_LABELS = { +        'cached_periods': _("Periods"),          'datings__period__label': _("Periods"),          'datings__period': _("Datings (period)"),          'detailled_related_context_records': _("Related context records"), @@ -337,6 +339,7 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,          'cached_label': 'cached_label__icontains',          'datings__period__label': 'datings__period__label',          'operation_id': 'operation_id', +        'unit__label': "unit__label"      }      RELATION_TYPES_PREFIX = {'ope_relation_types': 'operation__',                               'cr_relation_types': ''} @@ -424,6 +427,7 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,      HISTORICAL_M2M = [          'datings', 'documentations'      ] +    CACHED_LABELS = ['cached_label', 'cached_periods']      history = HistoricalRecords(bases=[HistoryModel])      objects = ExternalIdManager() @@ -508,6 +512,10 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,          verbose_name=_("Main image"), blank=True, null=True)      cached_label = models.TextField(_("Cached name"), null=True, blank=True,                                      db_index=True) +    cached_periods =  models.TextField( +        _("Cached periods label"), blank=True, null=True, +        help_text=_("Generated automatically - do not edit") +    )      class Meta:          verbose_name = _("Context Record") @@ -704,6 +712,10 @@ class ContextRecord(BulkUpdatedItem, DocumentItem, BaseHistorizedItem,      def _generate_cached_label(self):          return self.full_label() +    def _generate_cached_periods(self): +        return " & ".join([dating.period.label +                           for dating in self.datings.all()]) +      def _get_associated_cached_labels(self):          from archaeological_finds.models import Find, BaseFind          return list(Find.objects.filter(base_finds__context_record=self).all())\ | 
