gpt4 book ai didi

python - django 中 select_related() 和 select_related ('columnname' ) 之间的区别

转载 作者:太空狗 更新时间:2023-10-30 02:48:50 26 4
gpt4 key购买 nike

我很抱歉这个新手问题。我试图找出 select_related() 和 select_related('ColumnName') 之间的区别。这两者有区别吗?

我正在努力理解 this post其中作者强调使用 select_related('content_type').all() 而不是简单的 select_related().all()。感谢您的帮助,因为最近两个小时以来我一直在努力掌握这个概念。

非常感谢,

苏尼尔

最佳答案

来自django docs ,当不带参数调用时:

Returns a QuerySet that will automatically "follow" foreign-key relationships, selecting that additional related-object data when it executes its query.

当给出参数时:

Sometimes you only want to access specific models that are related to your root model, not all of the related models. In these cases, you can pass the related field names to select_related() and it will only follow those relations. You can even do this for models that are more than one relation away by separating the field names with double underscores, just as for filters.

关于python - django 中 select_related() 和 select_related ('columnname' ) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11317141/

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