Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the set.all () method of Association query in Django

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the associated query set.all () method in Django. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

For example, there are three a b c table relationships as follows: an is the parent of b and b is the parent of c

A > >.. = 'Lennon'NULL) but a legal object. .. = 'Lennon'Author model), if the corresponding author is not found in the Entry, it will be treated as having no name and will not raise an error because there is no author. When isnull. .. = TrueBlog objects include Blog objects whose author__name is empty, and objects whose author__name is not empty but the entry _ _ author associated with author__name is empty. .. = False=TrueManyToManyField or reverse ForeignKey to filter an object, there are two different kinds of filters. Blog/Entry association (Blog and Entry are one-to-many relationships). Blog is associated with multiple Entry, so both queries are possible and meaningful in some scenarios. ManyToManyField has a similar situation. Entry has a ManyToManyField called tags, and we may want to find Entry with tag called "music" and "bands", or we may want to find an Entry with tag name "music" and status "public". The filter () call. All the parameters in the filter () call are applied at the same time to filter out records that meet all requirements. The filter () call further restricts the set of objects, but for multi-valued relationships, they apply to the objects associated with the main model, rather than to the objects selected by the previous filter () call. .. = 'Lennon'=2008..='Lennon'.=2008Blog, not Entry. The behavior of the filter () query is different from that implemented by exclude (). The condition in the exclude () call does not have to refer to the same record. .. = 'Lennon'=2008filter () behaves differently, it does not exclude Entry that satisfies both conditions. The above is how to use the associated query set.all () method in Django. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report