title: How to get a duplicate instance on save in Django?
body: <p>Supposing I already have a created instance of a Django's model. I want to get another instance that is a duplicate in the database. Is there a universal way to do it without finding out which unique index is responsible for this duplication:</p>
  
  <pre><code>class MyModel(models.Model):
      ...
  
  instance = MyModel(...)
  print(instance.id)  # None
  
  ...
  
  duplicate = get_duplicate(instance)  # what should I type here instead of get_duplicate?
  print(duplicate.id)  # Some ID in DB
  </code></pre>
  
  <p>I want the function <code>get_duplicate</code> to not depend on the internal structure of the model. Also I don't want to modify the model.</p>
  
  <p>For example, if I need to find out a duplicate exists I can do <code>instance.save()</code>. In case of <code>IntegrityError</code> there's a duplicate. But how to find out which one?</p>