Filter built-in conditions for a Django query set

Source: Internet
Author: User

When the

condition is selected Queryset, filter indicates that =,exclude represents! =.
Queryset.distinct () to repeat
__exact exactly equals like ' aaa '
 __iexact exactly equals ignore case ilike ' AAA '
 __contains contains The like '%aaa% '
 __icontains contains the Ignore case ilike '%aaa% ', but for SQLite, the effect of contains is equivalent to Icontains.
__gt greater than
__gte greater than or equal to
__lt less than
__lte less than or equal to
__in present in a list range
__startswith to ... Start
__istartswith with ... Start ignoring case
__endswith with ... End
__iendswith with ... End, ignoring case
__range in ... Date in range
__year date field
__month Date field month
__day date field Day
__isnull=true/false

Example:
>> q1 = Entry.objects.filter (headline__startswith= "what")
>> q2 = q1.exclude (Pub_date__gte=datetime.date.today () )
>> q3 = Q1.filter (Pub_date__gte=datetime.date.today ())
>>> q = q.filter (pub_date__lte= Datetime.date.today ())
>>> q = q.exclude (body_text__icontains= "food")

that is Q1.filter (pub_date__gte =datetime.date.today ()) indicates that time >=now,q1.exclude (Pub_date__gte=datetime.date.today ()) is represented as <=now

Filter built-in conditions for a Django query set

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.