Skip to content

Instantly share code, notes, and snippets.

@f-ewald
Created May 9, 2017 19:11
Show Gist options
  • Select an option

  • Save f-ewald/24e41039ccf6168f067a7bdca17fb639 to your computer and use it in GitHub Desktop.

Select an option

Save f-ewald/24e41039ccf6168f067a7bdca17fb639 to your computer and use it in GitHub Desktop.
class OptimizationJob(models.Model):
def generate_primary_key():
no = randint(13537086546263552, 839299365868340223)
str_no = Base62.encode(no)
result_count = OptimizationJob.objects.filter(job_id=str_no).count()
while result_count > 0:
no = randint(13537086546263552, 839299365868340223)
str_no = Base62.encode(no)
result_count = OptimizationJob.objects.filter(job_id=str_no).count()
return str_no
job_id = models.CharField(max_length=10, primary_key=True, default=generate_primary_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment