Django query case-insensitive list match

前端 未结 7 1195
独厮守ぢ
独厮守ぢ 2020-12-03 09:21

I have a list of names that I want to match case insensitive, is there a way to do it without using a loop like below?

a = [\'name1\', \'name2\', \'name3\']
         


        
7条回答
  •  长情又很酷
    2020-12-03 10:22

    Another way to this using django query functions and annotation

    from django.db.models.functions import Lower
    Record.objects.annotate(name_lower=Lower('name')).filter(name_lower__in=['two', 'one']
    

提交回复
热议问题