summary
Query Format
模型类.objects.filter(字段__查询词=值)
The following describes the operation of the query words
View query set sql statement
查询集.query
Specifically, iexact
Equal to the query
Find multi-party, the wording of the conditions
I. multi foreign key table associated name is not defined
一方类名.objects.filter(多方类名小写__多方字段__查询词=值)
Case 2, the multi-table foreign key value associated with the name of a righteous write a related_query_name
一方类名.objects.filter(多方外键related_query_name的值__多方字段__查询词=值)
contains,icontains
Include Search
in
Find members
gt, lt, gte, lte
Compare Find
startswith, istartswith
Find the starting point
date, year etc.
Find a date
If the value of the date type datetime
If an int year equivalent
isnull
Sentenced empty
Boolean value
regex, iregex
Regular expression search
Detail
exact
Find exactly equivalent to equal
模型类.objects.filter(字段__exact=值)
- Explanation
- example
data sheet
Exact Match
result
- Case sensitivity when extended inquiry
- linux case sensitive utf8_bin, where 2
- windows are not sensitive
View sql statement
Describes how to view sql statement
查询集 = 模型类.objects.filter(查询条件)
查询集.query
-
Explanation
-
example
Inquire
result
iexact
The effect is equivalent exact, but it's fuzzy search
-
Explanation
-
example
result
- Supplement, like with =
name = 'John Doe'
versus
name like 'John Doe'
Slightly different
exact difference with iexact
contains 与 icontains
Query contains
With i indicates ignore case
- Explanation
- example
result
- And contains the exact difference
in
member
- Explanation
-
example
-
Example, find the id of the article 123 of classification
Test table
analysis
Now that classification to find
to find the classification table
here is to find relevance
Note
here the query
is
based on the classification, the article reverse lookup (foreign key in the article)
View to find
multi-row objects. Party class name in lowercase _set.all () to get all
Find query in
the multi-class name .objects.filter (party like the one name __ __ query term field = value)
In this way, search
Conditions reverse lookup
Multi-party find two ways to search
- Find common
多方类名.objects.filter(一方类名小写__一方字段__查询词=值)
Model class like this
This is the reverse lookup
notes
- If a foreign key is added a defined related_query_name
多方类名.objects.filter(一方类名外键related_query_name的值__一方字段__查询词=值)
Red frame reverse lookup table party
If on one side than the table id, you can not write __id
- All categories examples of what a pile of books
gt, lt, gte, lte
Greater than, less than, greater than or equal, less than or equal
-
Explanation
-
example
startswith, istartswith
To a certain start
- example
- summary
date, year
Time related types
- example
Extraction 2018. Article 4.4 is released
check sentence
Corresponding sql
日期字段_date = 日期时间对象
- 例子,year, month day week_day
Filtration time range
isnull
Sentenced to null
- Example, to find all the data empty date
Bool value is
- notes
Let me be
Regular expression search
- example
- notes