Queryset and objects classes in Python

Source: Internet
Author: User

One
1.queryset is a query set, which is the query content that is uploaded to the URL of the server. Django caches the result set Queryset returned by the query, which is designed to improve query efficiency. That is, when you create a Queryset object, Django does not immediately issue a query command to the database, only if you need to use this queryset.
2.Objects is the model class in M,django in the Django implementation of MVC has a objects object, which is an object of the Queryset type defined in Django that contains an instance of the model object.
3. No, because get may have an exception, you can use the filter function, as follows
>>> Entry.objects.filter (blog__id__exact=1) # shows the use of __exact
>>> Entry.objects.filter (blog__id=1) # implied use of __exact>>> Entry.objects.filter (blog__pk=1) # __PK Equivalent _ _id__exact
Query set of two, one is the browser input URL, server-side response, the URL is split into a query set, the dictionary to save the parameters and values of the Get and post. There is also the MVC pattern inside, the query results placed in the query set inside, just imagine a table on the line.


Two
Queryset is a class that is described in the documentation. For example, Objects.all () is returning. But sometimes the return is not queryset, this is another problem.  There is a wealth of information in Queryset. In addition to the data structures that are returned, you can also make an Extensible database query statement in conjunction with a metadata dictionary.

The objects should be a static class. Usually query a database with All,get,query and other methods. In order to improve efficiency, some filters can be added to reduce the amount of data queried, as well as to reduce re-query and index to improve efficiency.

For in list this is the syntax in the template. Lists can usually be obtained using objects.get, either query or get, or they can be re-assembled to form a list or a dict or something.

Objects.get is able to get an article, here to make an abnormal judgment (seems to be done), if you do not get the article will be reported abnormal. Pk= ... You can get a specific article.

Through the list in the for I in list, and then, the URL is passed through the view parameters, and then through the objects.get to get the article content, through another view and template display. It should be all right. These example codes are available in several tutorials. It's like Limodou's tutorial. Some old.
inquiry:
Then where do I go? What are the methods available for objects?
Chase Answer:
The question is well asked. Usually python has introspection. Directly with the Dir (...) method or object ...) You can see it. Use Help (...) can also be seen. But on this issue you go directly to the Www.djangoproject.com website, it has a tutor, and a library description. The description of this library has instructions for objects.

I used to have all, get, filter, query


From Baidu know: http://zhidao.baidu.com/link?url= fbmf7hej7dcwwfiectvgsgjj46ekbhtb6eufaasvl3eyazie2n0hpvyc44enmpl4sgwfcca-0yfqqkl8qmr-2a



Queryset and objects classes in Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.