I have two objects of the same class (Model) type. I want to check for an intersection on an M2M field. Is there an efficient way to do this without using raw SQL?
Here’s, basically, my current solution.
genres_a = [g for g in profile_a.genres.all()] # Convert to List
genres_b = set([g for g in profile_b.genres.all()]) # Convert to Set
if genres_b.intersection(genres_a): # Look for Intersection (Not Lazy)
print True # Do something...
If I understood intersection right: