Skip to content

Instantly share code, notes, and snippets.

@leewardbound
Last active August 29, 2015 13:58
Show Gist options
  • Save leewardbound/9945725 to your computer and use it in GitHub Desktop.
Save leewardbound/9945725 to your computer and use it in GitHub Desktop.
class CustomIDModel(models.Model):
named_id = models.CharField(max_length=128, primary_key=True, blank=True, editable=False)
def save(self, *args, **kwargs):
named_stub = '{0:6d}'.format(self.id).replace(' ', '0')
self.named_id = 'DS-' + named_stub[:3] + '-' + named_stub[3:3]
return super(CustomIDModel, self).save(*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment