75
update()
is converted directly to an SQL statement; it doesn’t call save()
on the model instances, and so the pre_save
and post_save
signals aren’t emitted. If you want your signal receivers to be called, you should loop over the queryset, and for each model instance, make your changes and call save()
yourself.
50
Just one more thing to @Ismali Badawi’s answer.
This calls post_save
user = User.objects.get(id=1)
user.username='edited_username'
user.save()
This does not call post_save
User.objects.filter(id=1).update(username='edited_username')
In the code,
from django.db.models.signals import post_save
@receiver(post_save, sender=User)
def do_something_when_user_updated(sender, instance, created, **kwargs):
if not created:
# User object updated
user_obj = instance
pass
- [Django]-Django-Bower + Foundation 5 + SASS, How to configure?
- [Django]-How to create a Django queryset filter comparing two date fields in the same model
- [Django]-Django: import auth user to the model
Source:stackexchange.com