Skip to content

Iterating over a or_ filter from a zip #440

Answered by collerek
igormorgado asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

I'm terribly sorry for staying silent for so long, had family emergency, plan to catch up in following days.

THANK YOU for your sponsorship, it means a lot and I really appreciate it 😁

You are almost there, you can unpack a list comprehension as both and_ and or_ expect positional arguments:

query = Book.objects.filter(
        ormar.or_(
            *[
                ormar.and_(author__name=name, year__gt=year)
                for name, year in
                zip(author_names, books_since)
            ]
        )
    )

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by igormorgado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants