From e9c45c71d16e4ca699d61bd638bf8b5832e10959 Mon Sep 17 00:00:00 2001 From: Arseniy Panfilov Date: Wed, 30 Sep 2020 21:31:24 -0400 Subject: [PATCH] update implementation of TimeStampedModel.save to handle various ways of specifying 'update_fields' --- model_utils/models.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/model_utils/models.py b/model_utils/models.py index fdf13a2..da7e879 100644 --- a/model_utils/models.py +++ b/model_utils/models.py @@ -34,8 +34,12 @@ class TimeStampedModel(models.Model): modified field is updated even if it is not given as a parameter to the update field argument. """ - if 'update_fields' in kwargs and 'modified' not in kwargs['update_fields']: - kwargs['update_fields'] += ['modified'] + update_fields = kwargs.get('update_fields', None) + if update_fields is not None: + update_fields = set(update_fields) + if update_fields: + kwargs['update_fields'] = update_fields.union({'modified'}) + super().save(*args, **kwargs) class Meta: