Django: How to access original (unmodified) instance in post_save signal

后端 未结 3 2062
一生所求
一生所求 2020-12-13 00:21

I want to do a data denormalization for better performance, and put a sum of votes my blog post receives inside Post model:

class Post(models.Model):
    \"\         


        
3条回答
  •  佛祖请我去吃肉
    2020-12-13 00:35

    I believe post_save is too late to retrieve the unmodified version. As the name implies the data has already been written to the db at that point. You should use pre_save instead. In that case you can retrieve the model from the db via pk: old = Vote.objects.get(pk=instance.pk) and check for differences in the current instance and the previous instance.

提交回复
热议问题