class Item(models.Model):
...
class ItemSet(models.Model):
items = models.ManyToManyField(Item, related_name="itemsets")
I have a list of ItemSets. I want to find all Item objects where the Item object is in the “items” M2M field on at least one of the ItemSet objects.
How can I do this?
P.S. Here is what I have tried, but to no avail:
itemset_list = [itemset1, itemset2, itemset3]
items = Item.objects.filter(itemsets__in=itemset_list)
If you need your list of itemsets and you didn’t get them from a query, try this:
If you can get your itemset list by querying, that shortens it a little bit: