Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果您使用该queryset.delete()方法,Django 正在发送 pre/post_delete 信号,但它不应该也发送 pre/post_save onqueryset.update()吗?
queryset.delete()
queryset.update()
也许应该,但事实并非如此。.update()不会.save()对 QuerySet 中的单个对象调用该方法,而是在单个 SQL 调用中更新所有对象(UPDATE,碰巧)。由于它不使用.save(),因此调用保存前和保存后信号会不一致。我当然可以设想人们可能希望它这样做的用例,但我也可以设想人们不希望这样做的用例。在我看来,不调用保存前和保存后信号是正确的行为,因为它为程序员留下了更多的灵活性。手动触发这些信号并不难,我认为
.update()
.save()