我意识到,如果我通过删除项目(没关系),模型上的 object_set 不会更新filter().delete()
,但是我想更新_set
删除后的内容,以便通过:
def test_prefetch(self):
game = Game.objects.prefetch_related('bubble_set').get()
game.fill_board()
self.assertEqual(game.bubble_set.count(), game.width * game.height)
game.bubble_set.filter(x=5).delete()
# Fails
self.assertNotEqual(game.bubble_set.count(), game.width * game.height)
game = Game.objects.prefetch_related('bubble_set').get()