2

I'm using this snippet, that allows users to only need to enter an email address to register for my app: http://djangosnippets.org/snippets/686/

Things are almost working perfectly. The problem is when a user has an email address that's above 30 characters. I get a "Ensure this value has at most 30 characters (it has 40)." error.

This is because the username is only supposed to be 30 characters. Is there a simple way to just tell Django that the username can be longer? It seems like there should be a fairly straightforward override for this.

Brenden
  • 8,264
  • 14
  • 48
  • 78

2 Answers2

1

This actually isn't simple at all. This requires subclassing the User model and using that everywhere. I've never had to do it, for this case, but it would likely cause significant issues with the Admin interface. You could also edit django's source to pull it off (ick).

Or even use this solution: Can django's auth_user.username be varchar(75)? How could that be done?

It's quite ugly though.

You're probably better off writing an authentication backend to use the email field for authentication rather than using the username field. To populate the username (which is required) then you'd just generate some sort of random unique username maybe by hashing or using a UUID.

Community
  • 1
  • 1
John
  • 5,166
  • 27
  • 31
  • I'm also trying to register/authenticate with an email address, but I can't figure out how to handle the username. I removed the username from my template, but since it's a required field the form doesn't validate. I did create a custom registration backend to generate as hash of the user, but it never gets invoked because of the invalid form. Any ideas? – Raj Aug 13 '11 at 16:07
0

Hopefully this solution should help you : http://www.micahcarrick.com/django-email-authentication.html

sprezzatura
  • 472
  • 5
  • 17