From 71ddde7ef5b4c4f4f0c6845351bb5981a1f81a7b Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Fri, 28 Feb 2014 10:45:53 +0000 Subject: [PATCH 1/2] We can (now?) use value_to_string and avoid problems with custom fields. Signed-off-by: Chris Lamb --- cache_toolbox/core.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cache_toolbox/core.py b/cache_toolbox/core.py index 8abc16c..098ebfa 100644 --- a/cache_toolbox/core.py +++ b/cache_toolbox/core.py @@ -67,13 +67,8 @@ def get_instance(model, instance_or_pk, timeout=None, using=None): if field.primary_key: continue - if field.get_internal_type() == 'FileField': - # Avoid problems with serializing FileFields - # by only serializing the file name - file = getattr(instance, field.attname) - data[field.attname] = file.name - else: - data[field.attname] = getattr(instance, field.attname) + # Serialise the instance using the Field's own serialisation routines. + data[field.attname] = field.value_to_string(instance) if timeout is None: timeout = app_settings.CACHE_TOOLBOX_DEFAULT_TIMEOUT From b4508fa877357d726c1d13691f708d0b06d37d6a Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Sat, 8 Aug 2015 17:43:57 +0200 Subject: [PATCH 2/2] This is now model_name --- cache_toolbox/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache_toolbox/core.py b/cache_toolbox/core.py index 098ebfa..16b2cce 100644 --- a/cache_toolbox/core.py +++ b/cache_toolbox/core.py @@ -91,6 +91,6 @@ def instance_key(model, instance_or_pk): return '%s.%s:%d' % ( model._meta.app_label, - model._meta.module_name, + model._meta.model_name, getattr(instance_or_pk, 'pk', instance_or_pk), )