1

I'm trying to use an the 'update_fields' argument passed to signals in Django.

I've got something very simple for now, namely:

@receiver(pre_save, sender=models.UserAdmin)
@receiver(pre_save, sender=models.UserGroupAdmin)
def update_timestamps(sender, instance, update_fields, **kwargs):
    print(f'Update fields: {update_fields}')

update_fields shows as None no matter what is being updated, which indicates I've not understood something.

What am I missing?

HenryM
  • 5,557
  • 7
  • 49
  • 105
  • 4
    It looks like you want to find out which fields have changed, but that isn't what `update_fields` is for. The `update_fields` method allows you specify which fields to save when you call `save()`. If it's `None` in your signal, then it wasn't passed to the `save()` method when it was called. – Alasdair Apr 14 '20 at 12:37
  • 2
    Searching *django signal changed fields* brings up questions like [like](https://stackoverflow.com/questions/36719566/identify-the-changed-fields-in-django-post-save-signal) [these](https://stackoverflow.com/questions/1355150/when-saving-how-can-you-check-if-a-field-has-changed/28094442#28094442) that might help you. – Alasdair Apr 14 '20 at 12:39

1 Answers1

1

update_fields The set of fields to update as passed to Model.save(), or None if update_fields wasn’t passed to save().

update_fields just pass up fields that you have in set in save() method for update

They are not fields that are updated in particular case ( you could set few fields in this list but maybe only one of them will actually change in database)

iklinac
  • 14,944
  • 4
  • 28
  • 30