summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-12-20 19:49:52 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-11 17:30:46 +0100
commit330215cf864ad3a917d51d6be15d68f360c166dc (patch)
tree3ae604ef9a36c7edaac48530db753810324e5494 /archaeological_warehouse/models.py
parent35ba8c95c9e359be0346dd163a47dd4874dd0ecb (diff)
downloadIshtar-330215cf864ad3a917d51d6be15d68f360c166dc.tar.bz2
Ishtar-330215cf864ad3a917d51d6be15d68f360c166dc.zip
Manage main image: model, auto associate default image
Diffstat (limited to 'archaeological_warehouse/models.py')
-rw-r--r--archaeological_warehouse/models.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index 92eaf5d2f..3b157ee0c 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -23,7 +23,7 @@ from django.conf import settings
from django.contrib.gis.db import models
from django.core.urlresolvers import reverse
from django.db.models import Q
-from django.db.models.signals import post_save, post_delete
+from django.db.models.signals import post_save, post_delete, m2m_changed
from django.template.defaultfilters import slugify
from django.utils.translation import ugettext_lazy as _, pgettext_lazy, \
activate, deactivate
@@ -31,7 +31,8 @@ from django.utils.translation import ugettext_lazy as _, pgettext_lazy, \
from ishtar_common.data_importer import post_importer_action
from ishtar_common.models import Document, GeneralType, get_external_id, \
LightHistorizedItem, OwnPerms, Address, Person, post_save_cache, \
- ImageModel, DashboardFormItem, ExternalIdManager, ShortMenuItem
+ ImageModel, DashboardFormItem, ExternalIdManager, ShortMenuItem, \
+ document_attached_changed
from ishtar_common.utils import cached_label_changed
@@ -87,6 +88,9 @@ class Warehouse(Address, DashboardFormItem, OwnPerms,
documents = models.ManyToManyField(
Document, related_name='warehouses', verbose_name=_(u"Documents"),
blank=True)
+ main_image = models.ForeignKey(
+ Document, related_name='main_image_warehouses',
+ verbose_name=_(u"Main image"), blank=True, null=True)
external_id = models.TextField(_(u"External ID"), blank=True, null=True)
auto_external_id = models.BooleanField(
_(u"External ID is set automatically"), default=False)
@@ -252,6 +256,10 @@ class Warehouse(Address, DashboardFormItem, OwnPerms,
return
+m2m_changed.connect(document_attached_changed,
+ sender=Warehouse.documents.through)
+
+
class Collection(LightHistorizedItem):
name = models.CharField(_(u"Name"), max_length=200,
null=True, blank=True)