summaryrefslogtreecommitdiff
path: root/ishtar_common
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
commit3faf5f35c66737a5c9f40cfd868accc2c564c89f (patch)
tree2b68665be8838b42a46648244344dfd1302222cc /ishtar_common
parenteb15c546ed5af18bf1277c094fc814d84c76c4b7 (diff)
downloadIshtar-3faf5f35c66737a5c9f40cfd868accc2c564c89f.tar.bz2
Ishtar-3faf5f35c66737a5c9f40cfd868accc2c564c89f.zip
Cache: update cache when saving
Diffstat (limited to 'ishtar_common')
-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"
"""