title: get_or_create django model with ManyToMany field
body: <p>Suppose I have three django models:</p>
  
  <pre><code>class Section(models.Model):
      name = models.CharField()
  
  class Size(models.Model):
      section = models.ForeignKey(Section)
      size = models.IntegerField()
  
  class Obj(models.Model):
      name = models.CharField()
      sizes = models.ManyToManyField(Size)
  </code></pre>
  
  <p>I would like to import a large amount of Obj data where many of the sizes fields will be identical. However, since Obj has a ManyToMany field, I can't just test for existence like I normally would. I would like to be able to do something like this:</p>
  
  <pre><code>try:
      x = Obj(name='foo')
      x.sizes.add(sizemodel1) # these can be looked up with get_or_create
      ...
      x.sizes.add(sizemodelN) # these can be looked up with get_or_create
      # Now test whether x already exists, so I don't add a duplicate
      try:
          Obj.objects.get(x)
      except Obj.DoesNotExist:
          x.save()
  </code></pre>
  
  <p>However, I'm not aware of a way to get an object this way, you have to just pass in keyword parameters, which don't work for ManyToManyFields.</p>
  
  <p>Is there any good way I can do this? The only idea I've had is to build up a set of Q objects to pass to get:</p>
  
  <pre><code>myq = myq &amp; Q(sizes__id=sizemodelN.id)
  </code></pre>
  
  <p>But I am not sure this will even work...</p>