Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django filter queryset using a list

I have one table, table A that holds primary keys of all the objects in the table b.

if I store all the primary keys from table A in a list, then is it possible to get a list of all the objects in table B using the primary keys I have stored in a list.

For Example:

tableB.objects.filter(pks = list) 

is there any way I can construct a query set like the above that would get me a list of all the object with the primary keys?

like image 259
skidwa Avatar asked Dec 31 '25 07:12

skidwa


1 Answers

tableB.objects.filter(pk__in=list)

Docs: https://docs.djangoproject.com/en/2.1/ref/models/querysets/#in

like image 153
mingaleg Avatar answered Jan 03 '26 14:01

mingaleg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!