title: Django ManyToMany filtering by set size or member in the set
body: <p>I am using <code>django</code> to maintain a database of messages.<br>
  Among others I have the following <em>models</em>:  </p>
  
  <pre><code>class User(models.Model):
      id = models.IntegerField(primary_key=True)
      name = models.CharField(max_length=10)
  
  class Message(models.Model):
      id = models.IntegerField(primary_key=True)
      body = models.CharField(max_length=200)
      users = models.ManyToManyField(User)
  </code></pre>
  
  <p>I am trying to write a utility method that for a given user gives me the messages he (and he alone) is associated with.</p>
  
  <p>i.e. for:  </p>
  
  <pre><code>m1 = Message(id=1, body='Some body')
  m1.save()
  m2 = Message(id=2, body='Another body')
  m2.save()
  m3 = Message(id=3, body='And yet another body')
  m3.save()
  
  u1 = User(name='Jesse James')
  u1.save()
  u2 = User(name='John Doe')
  u2.save()
  
  m1.users.add(u1, u2)
  m2.users.add(u1)
  m3.users.add(u2)
  
  getMessagesFor('Jesse James')
  </code></pre>
  
  <p>Will return only <code>m2</code>.<br>
  Assuming I have in <code>user</code> the right model instance, it boils down to one line, and I have tried these following:  </p>
  
  <pre><code>    user.message_set.annotate(usr_cnt=Count('users')).filter(usr_cnt__lte=1)
  </code></pre>
  
  <p>Or:  </p>
  
  <pre><code>    messages = Message.objects.filter(users__id__in=[user.id])
  </code></pre>
  
  <p>And:  </p>
  
  <pre><code>    messages = Message.objects.filter(users__id__exact=user.id)
  </code></pre>
  
  <p>And:  </p>
  
  <pre><code>    messages = Message.objects.filter(users__contains=user)
  </code></pre>
  
  <p>And so on... I always get both <code>m2</code> <strong>AND</strong> <code>m1</code>.<br>
  Tried annotations, excludes, filters etc.</p>
  
  <p>Can someone help me with this?</p>