Hi at all,
Is there a way to completly remove or disable username in Django ?
I want to use only email and password.
. Thanks ^_^
Hi at all,
Is there a way to completly remove or disable username in Django ?
I want to use only email and password.
. Thanks ^_^
You can't disable it, but you can generate a random or email-address-derived placeholder username when the user registers using an email address. Something like this in your reg form's clean() method will make a unique username from an email address (cos you can't have usernames with nonalphanumerics):
highest_user_id = User.objects.all().order_by('-id')[0].id #or something more efficient
leading_part_of_email = user_email.split('@',1)[0]
leading_part_of_email = re.sub(r'[^a-zA-Z0-9+]', '', leading_part_of_email) #remove non-alphanumerics
truncated_part_of_email = leading_part_of_email[:3] + leading_part_of_email[-3:] #first three and last three - will turn "[email protected]" into "abab" or b@ into "bb", which is ok
derived_username = '%s%s' % (truncated_part_of_email, highest_user_id+1)