diff options
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r-- | archaeological_warehouse/models.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 0eb19814d..0996a10e8 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -19,11 +19,14 @@ import datetime +from django.conf import settings from django.contrib.gis.db import models from django.db.models.signals import post_save, post_delete from django.template.defaultfilters import slugify from django.utils.translation import ugettext_lazy as _, ugettext +from ishtar_common.utils import cached_label_changed + from ishtar_common.models import GeneralType, \ LightHistorizedItem, OwnPerms, Address, Person, post_save_cache @@ -72,6 +75,11 @@ class Warehouse(Address, OwnPerms): return datetime.date.today().strftime('%Y-%m-%d') + '-' + \ slugify(unicode(self)) + def save(self, *args, **kwargs): + super(Warehouse, self).save(*args, **kwargs) + for container in self.containers.all(): + cached_label_changed(Container, {'instance': container}) + class WarehouseDivision(GeneralType): class Meta: @@ -128,16 +136,24 @@ class Container(LightHistorizedItem): verbose_name=_("Container type")) reference = models.CharField(_(u"Container ref."), max_length=40) comment = models.TextField(_(u"Comment")) + cached_label = models.CharField(_(u"Cached name"), max_length=500, + null=True, blank=True) class Meta: verbose_name = _(u"Container") verbose_name_plural = _(u"Containers") + ordering = ('cached_label',) def __unicode__(self): lbl = u" - ".join((self.reference, unicode(self.container_type), unicode(self.location))) return lbl + def _generate_cached_label(self): + items = [self.reference, self.precise_location] + cached_label = u" | ".join(items) + return cached_label + @property def associated_filename(self): return datetime.date.today().strftime('%Y-%m-%d') + '-' + \ @@ -149,11 +165,13 @@ class Container(LightHistorizedItem): def precise_location(self): location = unicode(self.location) locas = [ - u"{} {}".format(loca.division.division, loca.reference) - for loca in ContainerLocalisation.objects.filter( - container=self) + u"{} {}".format(loca.division.division, loca.reference) + for loca in ContainerLocalisation.objects.filter( + container=self) ] - return location + u" - " + u", ".join(locas) + return location + u" | " + u", ".join(locas) + +post_save.connect(cached_label_changed, sender=Container) class ContainerLocalisation(models.Model): @@ -172,3 +190,7 @@ class ContainerLocalisation(models.Model): lbl = u" - ".join((unicode(self.container), unicode(self.division), self.reference)) return lbl + + def save(self, *args, **kwargs): + super(ContainerLocalisation, self).save(*args, **kwargs) + cached_label_changed(Container, {'instance': self.container}) |