views:

37

answers:

1

Hi at all,

Is there a way to completly remove or disable username in Django ?

I want to use only email and password.

. Thanks ^_^

+1  A: 

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)
stevejalim
In other words, "don't go against the framework".
Max A.
Well, you could always make a copy of `django.contrib.auth`, go through it, get rid of `username` in the model and replace every reference of `username` with `email`. That's the brute-force way, since authentication isn't really "built-in" to Django.
Mike D.