Commit 2e0107c8 authored by Akshay Karthik's avatar Akshay Karthik
Browse files

re-add loop

parent f91f0011
...@@ -37,14 +37,14 @@ class URL( models.Model ): ...@@ -37,14 +37,14 @@ class URL( models.Model ):
hashids_counter += 1 hashids_counter += 1
short = hashids.encrypt(hashids_counter) short = hashids.encrypt(hashids_counter)
tries = 1 tries = 1
try: while tries < 100:
urls = URL.objects.get( short__iexact = short ) try:
tries += 1 urls = URL.objects.get( short__iexact = short )
hashids_counter += 1 tries += 1
except URL.DoesNotExist: hashids_counter += 1
return short except URL.DoesNotExist:
if tries > 100: return short
return None return None
# this needs to be here instead of at the top because the model's manager must be available before this line # this needs to be here instead of at the top because the model's manager must be available before this line
hashids_counter = URL.objects.count() hashids_counter = URL.objects.count()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment