title: Django - SQL bulk get_or_create possible?
body: <p>I am using <strong>get_or_create</strong> to insert objects to database but the problem is that doing 1000 at once takes too long time.</p>
  
  <p>I tried <strong>bulk_create</strong> but it doesn't provide functionality I need (creates duplicates, ignores unique value, doesn't trigger post_save signals I need).</p>
  
  <p>Is it even possible to do get_or_create in bulk via customized sql query? </p>
  
  <p>Here is my example code:</p>
  
  <pre><code>related_data = json.loads(urllib2.urlopen(final_url).read())
  
  for item in related_data:
  
      kw = item['keyword']
      e, c = KW.objects.get_or_create(KWuser=kw, author=author)
      e.project.add(id)
      #Add m2m to parent project
  </code></pre>
  
  <p>related_data cotains 1000 rows looking like this:</p>
  
  <pre><code>[{"cmp":0,"ams":3350000,"cpc":0.71,"keyword":"apple."},
  {"cmp":0.01,"ams":3350000,"cpc":1.54,"keyword":"apple -10810"}......]
  </code></pre>
  
  <p>KW model also sends signal I use to create another parent model:</p>
  
  <pre><code>@receiver(post_save, sender=KW)
  def grepw(sender, **kwargs):
      if kwargs.get('created', False):
          id = kwargs['instance'].id
          kww = kwargs['instance'].KWuser
          # KeyO 
          a, b = KeyO.objects.get_or_create(defaults={'keyword': kww}, keyword__iexact=kww)
          KW.objects.filter(id=id).update(KWF=a.id)
  </code></pre>
  
  <p>This works but as you can imagine doing thousands of rows at once takes long time and even crashes my tiny server, what bulk options do I have?</p>