F,更新时用于获取原来的值
# from django.db.models import F,Q
# models.UserInfo.objects.all().update(age=F("age")+1)
Q,用于构造复杂查询条件
# 应用一:
# models.UserInfo.objects.filter(Q(id__gt=1))
# models.UserInfo.objects.filter(Q(id=8) | Q(id=2))
# models.UserInfo.objects.filter(Q(id=8) & Q(id=2))
# 应用二:
# q1 = Q()
# q1.connector = 'OR'
# q1.children.append(('id__gt', 1))
# q1.children.append(('id', 10))
# q1.children.append(('id', 9))
#
#
# q2 = Q()
# q2.connector = 'OR'
# q2.children.append(('c1', 1))
# q2.children.append(('c1', 10))
# q2.children.append(('c1', 9))
#
# q3 = Q()
# q3.connector = 'AND'
# q3.children.append(('id', 1))
# q3.children.append(('id', 2))
# q2.add(q3,'OR')
#
# con = Q()
# con.add(q1, 'AND')
# con.add(q2, 'AND')
# models.UserInfo.objects.filter(con)