title: Django: Override save method to handle unique=True IntegrityError
body: <p>My model has a <code>CharField</code> that defaults to a randomly generated string which should be unique. I don't want to use a <code>UUIDField</code>. Is there a way to override the save method to handle <code>IntegrityError</code> raised if the code generated is a duplicate? Or should I check for that in my generation function?</p>
  
  <p><strong>MODEL</strong></p>
  
  <pre><code>class Item(models.Model):
      ...
      item_code = models.CharField(max_length=11, default=get_generated_code, unique=True)
  </code></pre>
  
  <p><strong>FUNCTION</strong></p>
  
  <pre><code>def get_generated_code():
      code = ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(11))
      return code
  </code></pre>