summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-18 18:01:15 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-01-18 18:01:15 +0100
commitd1dad918bb5cb3e70d72d6ad0b8a659fdcc26266 (patch)
treed9490199faba5920aeac7d5a65f81a52f252d56c /ishtar_common/models.py
parent55270f2f3be966f0454968434bcb9a04617fbe6d (diff)
downloadIshtar-d1dad918bb5cb3e70d72d6ad0b8a659fdcc26266.tar.bz2
Ishtar-d1dad918bb5cb3e70d72d6ad0b8a659fdcc26266.zip
Manage index and external id for documents
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index 4078b5840..769013fa2 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -3762,6 +3762,7 @@ post_delete.connect(post_save_cache, sender=LicenseType)
class Document(BaseHistorizedItem, OwnPerms, ImageModel):
+ EXTERNAL_ID_KEY = 'document_external_id'
# order is important: put the image in the first match found
# other will be symbolic links
RELATED_MODELS = [
@@ -4146,9 +4147,23 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel):
def _generate_cache_related_label(self):
return self.related_label()
+ def set_index(self):
+ if self.index:
+ return
+ q = Document.objects.values('index').filter(
+ index__isnull=False).order_by("-index")
+ if not q.count():
+ self.index = 1
+ return
+ cid = q.all()[0]['index']
+ if not cid:
+ cid = 0
+ self.index = cid + 1
+
def save(self, *args, **kwargs):
no_path_change = 'no_path_change' in kwargs \
and kwargs.pop('no_path_change')
+ self.set_index()
super(Document, self).save(*args, **kwargs)
if self.image and not no_path_change and \