There's another F and a Q in Django.
How to Import
From Django.db.models import F
About F:
How to use
F more say, he is used to specify the fields in the table,
For example, when the Size field in TABLE01 plus 1,
The statement in SQL is
Update table01 Set size = Size +1
In Django, it's
Models.table01.objects.all (). Update (size = F ("size") +1)
F ("size") represents the size of the current row, which is the function of F.
About Q
For conditional queries
Like some websites provide advanced searches that specify multiple search criteria, you can do so with Q.
How to use:
From Django.db.models import Q
Condition1 = Q ()
Condition2 = Q ()
Condition3 = Q ()
# set Condition1, multiple conditions, or relationships, or you can set other relationships
Condition1.connector = "OR"
Condition1.children.append (("id", 1))
Condition1.children.append (("id", 3))
# set Condition2, multiple conditions, or relationships, or you can set other relationships
Condition2.connector = "OR"
Condition2.children.append (("Name", "Alex"))
Condition2.children.append (("name", "Eric")
#将 Condition1 and Condition2 together and put them in Condition3.
Condition3.add (Condition1, "add")
Condition3.add (Condition2, "add")
# Make a conditional query.
Models. TableName.objects.filter (Condition3)
This article is from the "'ll Notes" blog, so be sure to keep this source http://timesnotes.blog.51cto.com/1079212/1766023
Python Learning Note-day022-f,q