Django efficient bulk_create with unique constraint
<p>I searched for this and there appears to be no really good solution(most answers are years old). Is there any new good solution for bulk_creating objects that need to be unique ?</p>

<p>Ok, so I have lists containing ~1000 dicts and unique constraint on dict['keyword']. So far I've been doing it this way:</p>

<pre><code>self.get_existing_KeyO = \
list(KeyO.objects.filter(keyword__in=[x['keyword'] for x in self.data]).all())
</code></pre>

<p>And then I bulk_create those that are not already in database. I am using django 1.10 (because I need ID's of created objects)</p>

<p>I am doing this with celery (multiple threads) so there are conflicts(two threads adding to database at the same time). Could get_or_create be more efficient? I am slightly afraid it will crash DB as sometimes I am adding 5-10 lists at the same time, which would result in ~10 000 queries.</p>