summaryrefslogtreecommitdiff
path: root/ishtar_common/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-25 12:36:33 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-25 12:36:33 +0200
commit6cd180a97f8914a27d6e703a59dec8e7661cf99b (patch)
tree2b68665be8838b42a46648244344dfd1302222cc /ishtar_common/models.py
parentae8a81de6b6786518027ccd8f09e825d107be5e7 (diff)
downloadIshtar-6cd180a97f8914a27d6e703a59dec8e7661cf99b.tar.bz2
Ishtar-6cd180a97f8914a27d6e703a59dec8e7661cf99b.zip
Cache: update cache when saving
Diffstat (limited to 'ishtar_common/models.py')
-rw-r--r--ishtar_common/models.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index a1cc3cc1b..51cb16157 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -258,9 +258,9 @@ class Cached(object):
slug_field = 'txt_idx'
@classmethod
- def get_cache(cls, slug):
+ def get_cache(cls, slug, force=False):
cache_key, value = get_cache(cls, slug)
- if value:
+ if not force and value:
return value
try:
k = {cls.slug_field: slug}
@@ -270,8 +270,13 @@ class Cached(object):
except cls.DoesNotExist:
return None
+ def save(self, *args, **kwargs):
+ ret = super(Cached, self).save(*args, **kwargs)
+ self.get_cache(getattr(self, self.slug_field), force=True)
+ return ret
+
-class GeneralType(models.Model, Cached):
+class GeneralType(Cached, models.Model):
"""
Abstract class for "types"
"""