1

我意识到,如果我通过删除项目(没关系),模型上的 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()
4

1 回答 1

0

您需要重新获取对象。所以可以做game = Game.objects.prefetch_related('bubble_set').get()之后.delete()

于 2012-07-16T07:16:02.730 回答