summaryrefslogtreecommitdiff
path: root/archaeological_finds/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-09 12:36:11 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-09-09 12:36:11 +0200
commit19aca26153c716737dffd48effbb98a6a4540caf (patch)
tree35ccee103e5debfd9ce33e75321fa97eff817091 /archaeological_finds/models.py
parentf5f538dad1837c6393c93d092e69b13a2ec3e34b (diff)
downloadIshtar-19aca26153c716737dffd48effbb98a6a4540caf.tar.bz2
Ishtar-19aca26153c716737dffd48effbb98a6a4540caf.zip
Cached label for context records and finds
Diffstat (limited to 'archaeological_finds/models.py')
-rw-r--r--archaeological_finds/models.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/archaeological_finds/models.py b/archaeological_finds/models.py
index 0f069e1d8..d266bba76 100644
--- a/archaeological_finds/models.py
+++ b/archaeological_finds/models.py
@@ -23,9 +23,11 @@ from django.conf import settings
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
from django.db.models import Max, Q
-from django.db.models.signals import m2m_changed
+from django.db.models.signals import m2m_changed, post_save
from django.utils.translation import ugettext_lazy as _, ugettext
+from ishtar_common.utils import cached_label_changed
+
from ishtar_common.models import GeneralType, ImageModel, BaseHistorizedItem, \
ShortMenuItem, LightHistorizedItem, HistoricalRecords, OwnPerms, Source, \
Person, Basket, get_external_id
@@ -375,6 +377,7 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
default=datetime.date.today)
estimated_value = models.FloatField(_(u"Estimated value"), blank=True,
null=True)
+ cached_label = models.TextField(_(u"Cached name"), null=True, blank=True)
history = HistoricalRecords()
BASKET_MODEL = FindBasket
IMAGE_PREFIX = 'finds/'
@@ -389,13 +392,18 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
("change_own_find", ugettext(u"Can change own Find")),
("delete_own_find", ugettext(u"Can delete own Find")),
)
+ ordering = ('cached_label',)
@property
def short_class_name(self):
return _(u"FIND")
def __unicode__(self):
- return self.label
+ lbl = settings.JOINT.join([
+ getattr(self, attr)
+ for attr in ('administrative_index', 'label')
+ if getattr(self, attr)])
+ return lbl
@property
def short_label(self):
@@ -573,6 +581,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
owns = super(Find, cls).get_owns(user, extra_query=extra_query)
return sorted(owns, key=lambda x: x.cached_label)
+ def _generate_cached_label(self):
+ return unicode(self)
+
def save(self, *args, **kwargs):
super(Find, self).save(*args, **kwargs)
@@ -633,6 +644,9 @@ class Find(BaseHistorizedItem, ImageModel, OwnPerms, ShortMenuItem):
# idx and idx['material_index__max'] + 1 or 1
+post_save.connect(cached_label_changed, sender=Find)
+
+
def base_find_find_changed(sender, **kwargs):
obj = kwargs.get('instance', None)
if not obj: