--- a/profile/forms.py Fri Jan 07 08:56:24 2011 +0530
+++ b/profile/forms.py Fri Jan 07 09:01:27 2011 +0530
@@ -76,6 +76,7 @@
gender=self.cleaned_data['gender'],
address=self.cleaned_data['address']
phonenum=self.cleaned_data['phonenum'],
+ uniq_key=make_key(Profile),
)
new_profile.save()
--- 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
+