summaryrefslogtreecommitdiff
path: root/archaeological_finds/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds/models.py')
-rw-r--r--archaeological_finds/models.py47
1 files changed, 23 insertions, 24 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index fe06b82bc..4259c7883 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -109,6 +109,12 @@ class BaseFind(BaseHistorizedItem, OwnPerms):
null=True)
index = models.IntegerField(u"Index", default=0)
material_index = models.IntegerField(u"Material index", default=0)
+ cache_short_id = models.TextField(
+ _(u"Short ID"), blank=True, null=True,
+ help_text=_(u"Cached value - do not edit"))
+ cache_complete_id = models.TextField(
+ _(u"Complete ID"), blank=True, null=True,
+ help_text=_(u"Cached value - do not edit"))
history = HistoricalRecords()
RELATED_POST_PROCESS = ['find']
@@ -225,40 +231,22 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
if settings.COUNTRY == 'fr':
TABLE_COLS.insert(
6, 'base_finds.context_record.operation.code_patriarche')
- if settings.COUNTRY == 'fr':
- TABLE_COLS_FOR_OPE = [
- ['base_finds.context_record.operation.code_patriarche', ],
- ['base_finds.context_record.operation.code_patriarche', ],
- ]
- else:
- TABLE_COLS_FOR_OPE = [
- ['base_finds.context_record.operation.year',
- 'base_finds.context_record.operation.operation_code'],
- ['base_finds.context_record.operation.year',
- 'base_finds.context_record.operation.operation_code']
- ]
- TABLE_COLS_FOR_OPE[0] += ['index']
- TABLE_COLS_FOR_OPE[1] += [
- 'material_types.code',
- 'base_finds.context_record.label',
- 'index']
- TABLE_COLS_FOR_OPE += [
+ TABLE_COLS_FOR_OPE = [
+ 'base_finds.cache_short_id',
+ 'base_finds.cache_complete_id',
'previous_id', 'label', 'material_types',
'datings.period', 'find_number', 'object_types',
'description']
- TABLE_COLS_FOR_OPE_LBL = {
- 'code_patriarche__index': _("Short Id"),
- 'code_patriarche__code__label__index': _("Complete ID")}
EXTRA_FULL_FIELDS = [
- 'base_finds.short_id', 'base_finds.complete_id',
+ 'base_finds.cache_short_id', 'base_finds.cache_complete_id',
'base_finds.comment', 'base_finds.description',
'base_finds.topographic_localisation',
'base_finds.special_interest',
'base_finds.discovery_date']
EXTRA_FULL_FIELDS_LABELS = {
- 'base_finds.short_id': _(u"Base find - Short Id"),
- 'base_finds.complete_id': _(u"Base find - Complete ID"),
+ 'base_finds.cache_short_id': _(u"Base find - Short Id"),
+ 'base_finds.cache_complete_id': _(u"Base find - Complete ID"),
'base_finds.comment': _(u"Base find - Comment"),
'base_finds.description': _(u"Base find - Description"),
'base_finds.topographic_localisation': _(u"Base find - "
@@ -481,7 +469,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
self.index = 1
self.save()
for base_find in self.base_finds.all():
+ modified = False
if not base_find.index:
+ modified = True
cond = {
'context_record__operation':
base_find.context_record.operation}
@@ -490,6 +480,15 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
base_find.index = 1
if idx and idx['index__max']:
base_find.index = idx['index__max'] + 1
+ if not base_find.cache_short_id:
+ base_find.cache_short_id = base_find.short_id()
+ if base_find.cache_short_id:
+ modified = True
+ if not base_find.cache_complete_id:
+ base_find.cache_complete_id = base_find.complete_id()
+ if base_find.cache_complete_id:
+ modified = True
+ if modified:
base_find.save()
# if not base_find.material_index:
# idx = BaseFind.objects\