Let’s say I have the following classes:
class Votable(models.Model):
name = ...
class Vote(models.Model):
options = models.ManyToManyField(Votable, related_name='+')
choosen = models.ForeignKey(Votable)
Notes:
Vote.options have exactly 2 items
Vote.choosen is one of the 2 items of options
How do I make a query that search for the exact 2 items of Vote.options and also Vote.choosen?
I tried Vote.objects.get(options=[1,2], choosen=1) but it returns:
TypeError: int() argument must be a string or a number, not 'list'
You have to chain filters to get only vote objects that have both options 1 and 2.
If you wanted vote objects that had either
options1 OR 2 you’d use__insyntax: