summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py38
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),