diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-12-18 18:34:43 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-12-18 18:34:43 +0100 |
commit | 2d7e9cd3d49e918f37a30352f35d1ad4c2ace769 (patch) | |
tree | 617d32c1aaa8c85a4782aecfa64d075f598af0dc /archaeological_warehouse/models.py | |
parent | bd6026dfd15dc58958aff61ffac9ab08da0d49ee (diff) | |
download | Ishtar-2d7e9cd3d49e918f37a30352f35d1ad4c2ace769.tar.bz2 Ishtar-2d7e9cd3d49e918f37a30352f35d1ad4c2ace769.zip |
Containers / Warehouse: actions, sheets and fixes.
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r-- | archaeological_warehouse/models.py | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 57068f374..0872df220 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -17,8 +17,11 @@ # See the file COPYING for details. -from django.db.models.signals import post_save, post_delete +import datetime + 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.models import GeneralType, \ @@ -35,6 +38,7 @@ post_delete.connect(post_save_cache, sender=WarehouseType) class Warehouse(Address, OwnPerms): + SHOW_URL = 'show-warehouse' name = models.CharField(_(u"Name"), max_length=200) warehouse_type = models.ForeignKey(WarehouseType, verbose_name=_(u"Warehouse type")) @@ -63,11 +67,18 @@ class Warehouse(Address, OwnPerms): def __unicode__(self): return u"%s (%s)" % (self.name, unicode(self.warehouse_type)) + @property + def associated_filename(self): + return datetime.date.today().strftime('%Y-%m-%d') + '-' + \ + slugify(unicode(self)) + class WarehouseDivision(GeneralType): class Meta: verbose_name = _(u"Warehouse division") verbose_name_plural = _(u"Warehouse divisions") +post_save.connect(post_save_cache, sender=WarehouseDivision) +post_delete.connect(post_save_cache, sender=WarehouseDivision) class WarehouseDivisionLink(models.Model): @@ -80,6 +91,9 @@ class WarehouseDivisionLink(models.Model): ordering = ('warehouse', 'order') unique_together = ('warehouse', 'division') + def __unicode__(self): + return u"{} - {}".format(self.warehouse, self.division) + class ContainerType(GeneralType): length = models.IntegerField(_(u"Length (mm)"), blank=True, null=True) @@ -105,9 +119,11 @@ class Container(LightHistorizedItem): 'container_type': 'container_type__pk', 'reference': 'reference__icontains', } + SHOW_URL = 'show-container' # fields - location = models.ForeignKey(Warehouse, verbose_name=_(u"Warehouse")) + location = models.ForeignKey(Warehouse, verbose_name=_(u"Warehouse"), + related_name='containers') container_type = models.ForeignKey(ContainerType, verbose_name=_("Container type")) reference = models.CharField(_(u"Container ref."), max_length=40) @@ -122,6 +138,23 @@ class Container(LightHistorizedItem): unicode(self.location))) return lbl + @property + def associated_filename(self): + return datetime.date.today().strftime('%Y-%m-%d') + '-' + \ + "-".join([str(slugify(getattr(self, attr))) + for attr in ('location', 'container_type', + 'reference')]) + + @property + def precise_location(self): + location = unicode(self.location) + locas = [ + u"{} {}".format(loca.division.division, loca.reference) + for loca in ContainerLocalisation.objects.filter( + container=self) + ] + return location + u" - " + u", ".join(locas) + class ContainerLocalisation(models.Model): container = models.ForeignKey(Container, verbose_name=_(u"Container")) @@ -133,6 +166,7 @@ class ContainerLocalisation(models.Model): verbose_name = _(u"Container localisation") verbose_name_plural = _(u"Container localisations") unique_together = ('container', 'division') + ordering = ('container', 'division__order') def __unicode__(self): lbl = u" - ".join((unicode(self.container), |