summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--profile/forms.py1
-rw-r--r--utils.py11
2 files changed, 9 insertions, 3 deletions
diff --git a/profile/forms.py b/profile/forms.py
index 403d8c8..f4351a9 100644
--- a/profile/forms.py
+++ b/profile/forms.py
@@ -76,6 +76,7 @@ class RegistrationFormCustom(RegistrationFormUniqueEmail):
gender=self.cleaned_data['gender'],
address=self.cleaned_data['address']
phonenum=self.cleaned_data['phonenum'],
+ uniq_key=make_key(Profile),
)
new_profile.save()
diff --git a/utils.py b/utils.py
index a220264..3ca1ab0 100644
--- a/utils.py
+++ b/utils.py
@@ -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