Django objects. all (), objects. get (), objects. filter (), djangoobjects. all

Source: Internet
Author: User

Django objects. all (), objects. get (), objects. filter (), djangoobjects. all

Ret = UserInfo. objects. all () all returns the QuerySet object. The program does not actually execute SQL statements in the database to query data, but supports iteration. You can use the for loop to obtain data. Ret = UserInfo. objects. get (id = '1') get returns the Model object and the type is list. This means that the get method will directly execute the SQL statement to obtain the data ret = UserInfo. objects. filter () is similar to get, but supports more powerful query functions.

Supplement:
When querySet is selected as a condition, filter indicates = and exclude indicates! =.

QuerySet. distinct () deduplication
_ Exact is exactly like 'aaa'
_ Iexact is exact equal to ignoring the upper and lower case ilike 'aaa'
_ Contains include like '% aaa %'
_ Icontains indicates that ilike '% aaa %' is case-insensitive. However, for sqlite, the effect of contains is equivalent to that of icontains.
_ Gt greater
_ Gte greater than or equal
_ Lt is less
_ Equal to or less than lte
_ In exists in a list range.
_ Startswith starts...
_ Istartswith starts with... and ignores case sensitivity.
_ Endswith ends...
_ Iendswith ends with..., case insensitive
_ Range is within the range...
_ Year of the Date Field
_ Month
_ Day of the Date Field
_ Isnull = True/False

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.