1 方法一: 2 id_list = [1, 2, 3, 4] 3 TestModel.objects.filter(id__in=id_list)
4 方法二: 5 from django.db.models import Q 6 sql = Q() 7 for id in id_list: 8 sql |= Q(id=id) 9 TestModel.objects.filter(sql)
1 方法一: 2 id_list = [1, 2, 3, 4] 3 TestModel.objects.filter(id__in=id_list)
4 方法二: 5 from django.db.models import Q 6 sql = Q() 7 for id in id_list: 8 sql |= Q(id=id) 9 TestModel.objects.filter(sql)