Django 'objects.filter()' with list?

前端 未结 2 2229
醉梦人生
醉梦人生 2020-12-24 07:33

It is possible to limiting QuerySet in this kind of way:

creators_list = [\'jane\', \'tarzan\', \'chita\']
my_model.objects.filter(creator=creators_list)
         


        
2条回答
  •  梦毁少年i
    2020-12-24 08:06

    Also if you're using sqlite and running into problems, there exists a limitation for the max number of items in the list.

    def divideChunks(l, n):
        for i in range(0, len(l), n):
            yield l[i:i + n]
    
    for slicerange in divideChunks(objs, 10):
            myobjects = my_model.objects.filter(creator__in = slicerange)
            ...
    

提交回复
热议问题