django查询的一些操作

# and的关系
# queryset = Projects.objects.filter(name__contains="TG2.62",tester='wxb')

# 或者的关系
# queryset = Projects.objects.filter(Q(name__contains="TG2.62")|Q(tester='wxb'))
# queryset = Projects.objects.filter(Q(name__contains="TG2.62",tester='wxb')|Q(desc="托管老产品1"))

# 分组查询annotate,相当于SELECT `tb_projects`.`name`, `tb_projects`.`id` FROM `tb_projects` GROUP BY `tb_projects`.`id` ;
queryset = Projects.objects.annotate(Count("name")).values('name',"id")
# 聚合函数aggregate,想当于SELECT COUNT(`tb_projects`.`name`) AS `name__count`, COUNT(`tb_projects`.`id`) AS `id__count` FROM `tb_projects` WHERE `tb_projects`.`name` LIKE BINARY '%TG2.62%'"
# queryset = Projects.objects.filter(name__contains="TG2.62").aggregate(Count("name"),Count('id'))
print(queryset)
res_list = []

你可能感兴趣的:(django,django,python,后端)