Given the following two models:
class Card(models.Model):
disabled = models.BooleanField(default=False)
class User(models.Model):
owned_cards = models.ManyToManyField(Card)
Given a certain user, how can I, in one query, get all the Card objects that are not disabled, and are also present in that user’s owned_cards field?
It’s actually quite simple, you can use the owned_cards field of a user object as a manager.
Answer for the second question in the comments, this should work, using Q objects to negate the lookup.