diff --git a/cache_toolbox/core.py b/cache_toolbox/core.py index 8abc16c..16b2cce 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 @@ -96,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), )