gpt4 book ai didi

django - Django 中的 query.clone()、queryset.clone() 是什么?

转载 作者:行者123 更新时间:2023-12-02 16:27:11 28 4
gpt4 key购买 nike

我看到clone()在django代码中被广泛使用

queryset.query.clone()  
queryset.clone()

它的用途是什么?我应该模仿查询集或管理器方法中的行为吗?

最佳答案

正如凯文在 his answer 中指出的那样,clone() 方法不是 Django API 的文档部分。然而,all() method已完整记录,并且可以执行您可能希望通过 clone() 实现的操作。

all()

Returns a copy of the current QuerySet (or QuerySet subclass). This can be useful in situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. After calling all() on either object, you’ll definitely have a QuerySet to work with.

When a QuerySet is evaluated, it typically caches its results. If the data in the database might have changed since a QuerySet was evaluated, you can get updated results for the same query by calling all() on a previously evaluated QuerySet.

关于django - Django 中的 query.clone()、queryset.clone() 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21385248/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com