Django filter queryset on “tuples” of values for multiple columns

后端 未结 3 1559
孤独总比滥情好
孤独总比滥情好 2021-02-04 01:40

Say I have a model:

Class Person(models.Model):
    firstname = models.CharField()
    lastname = models.CharField()
    birthday = models.DateField()
    # etc.         


        
3条回答
  •  余生分开走
    2021-02-04 02:18

    I don't see much solutions except for a big OR clause:

    import operator
    from itertools import izip
    query = reduce(
        operator.or_, 
        (Q(firstname=fn, lastname=ln) for fn, ln in izip(first_list, last_list))
        )
    
    Person.objects.filter(query)
    

提交回复
热议问题