diff options
Diffstat (limited to 'archaeological_finds/models.py')
-rw-r--r-- | archaeological_finds/models.py | 18 |
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: |