Django uses or conditional queries and various query keywords


Django uses or condition query:

from django.db.models import Q

User.objects.filter(Q(state=0) | Q(state=1))

Django query keywords:

__ Exact equals like ‘AAA’
__ Iexact is exactly the same as ignore case like ‘AAA’
__ Contains contains like% AAA%
__ Icontains contains ignore case like ‘% AAA%’, but for SQLite, the effect of contains is equivalent to icontains.
__ GT greater than
__ GTE greater than or equal to
__ Lt is less than
__ LTE less than or equal to
__ In exists in a list scope
__ Start switch to start
__ Istartswitch to Ignore case at the beginning
__ Endswith to ending
__ Friends with End, ignore case
__ Range in In scope
__ The year of the year date field
__ The month of the month date field
__ The day of the day date field

User.objects.filter (state__ GT = 0) / / the query status is greater than 0
User.objects.filter (state__ Isnull = true) / / the query status is empty