Beware Django Query Filter update() not using save validation


Always remember when using this script :

1
Member.objects.filter(…).update({‘phone’: ‘082343-324234’})

If you have validation or rules in Model save(), then it will not being called.
REMEMBER that update() in filter will not emit any signal and pass save model.

To update model with kwargs, we can use :

1
2
 instance.__dict__.update(member)
 instance.save()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.