changeset 15 | beb830b0e744 |
parent 13 | 1773b48559e1 |
--- a/utils.py Fri Jan 07 08:56:24 2011 +0530 +++ b/utils.py Fri Jan 07 09:01:27 2011 +0530 @@ -1,8 +1,13 @@ import string,random -def make_key(): +def make_key(model_name): """ return a 10 character random key. """ - - return ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)]) + while True: + key = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)]) + try: + model_name.objects.get(uniq_key=key) + except model_name.DoesNotExist: + return key +