From f1f295e054fea72514f3dfa462a0c9d9ef2b53d7 Mon Sep 17 00:00:00 2001 From: Hannes Tismer Date: Mon, 24 Oct 2016 16:21:53 +0200 Subject: [PATCH] honor post_save's update_fields and only fire the source_saved signal when needed --- imagekit/specs/sourcegroups.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/imagekit/specs/sourcegroups.py b/imagekit/specs/sourcegroups.py index d8ea3a7..03a3322 100644 --- a/imagekit/specs/sourcegroups.py +++ b/imagekit/specs/sourcegroups.py @@ -87,12 +87,15 @@ class ModelSignalRouter(object): if isinstance(instance, src.model_class)) @ik_model_receiver - def post_save_receiver(self, sender, instance=None, created=False, raw=False, **kwargs): + def post_save_receiver(self, sender, instance=None, created=False, update_fields=None, raw=False, **kwargs): if not raw: self.init_instance(instance) old_hashes = instance._ik.get('source_hashes', {}).copy() new_hashes = self.update_source_hashes(instance) for attname in self.get_source_fields(instance): + if update_fields and attname not in update_fields: + continue + file = getattr(instance, attname) if file and old_hashes.get(attname) != new_hashes[attname]: self.dispatch_signal(source_saved, file, sender, instance,