diff options
-rw-r--r-- | profile/forms.py | 1 | ||||
-rw-r--r-- | utils.py | 11 |
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() @@ -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 |