I am having list (could be a set or another iterable) of, say, emails strings, and I want to get all of a models’ objects that have attribute ’email’ matching any of those emails.
I am doing:
from myapp.models import MyModel
l=['email1@x.com', 'email2@x.com', 'email3@y.com']
from django.db.models import Q
q = Q(email=l[0])
for e in l[1:]:
q |= Q(email=e)
MyModel.objects.get(q)
Is there a way to do it more elegantly?
you can use: