在检索updatedestroy方法中获取所有对象是一个好习惯吗?

发布于 2025-01-30 07:33:23 字数 214 浏览 1 评论 0原文

为什么我们需要将所有对象获取在检索方法中?

在实际项目中,即使有大数据,我也可以这样做吗?

Why we need to get all object in RetrieveUpdateDestroy Method?

In real project can I do it just like this Without fear even if there is large data?
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2025-02-06 07:33:23

为什么[做]我们需要在[a] retieveupdatedestroy [view]?

中获取所有对象[s]?

我们:querySet是未评估的。这仅用作“父” QuerySet来制作QuerySet来检索,更新和删除单个对象。

实际上,对于检索方法,它将在末尾添加.get> .get(pk = some_pk),因此请查询检索该单个对象。

QuerySet可用于过滤某些项目,以防止检索,更新和删除某些对象。例如,您可以使用querySet = student.objects.filter(active = true)只能检索Active student s。

Why [do] we need to get all object[s] in [a] RetrieveUpdateDestroy [view]?

We don't: the queryset is not evaluated. This is only used as a "parent" queryset to make querysets to retrieve, update, and delete a single object.

Indeed, for a retrieve method, it will add .get(pk=some_pk) at the end, and thus make a query to retrieve that single object.

The queryset can be used to filter certain items, to prevent retrieving, updating and removing certain objects for example. You can for example use queryset = Student.objects.filter(active=True) to only be able to retrieve active Students.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文