I am given a list like so
a = [1, 2, 3, 4]
This list matches the id's stored in a django model we will call Books.
I am trying to return a queryset of Books with the id's in the list. I am thinking of using Q objects and grab them by doing something like this
Books.objects.filter(Q(id = 1) | Q(id=2) | Q(id=3) | Q(id=4))
Now i would just use the index like this:
Books.objects.filter(Q(id = a[0]) | Q(id=a[1]) | Q(id=a[2]) | Q(id=a[3]))
BUT, These list will be varying in length up to around 30 and hardcoding the index wont work, and hardcoding the query won't satisfy the varying length of lists.
Is it possible to go this route? And if so, how can I accomplish returning the books with the id's that match the list?