We use a base64 or base36 (if you want compatibility with the contrib.admin) encoded UUID, or generate a random 30-character string, the odds of a collision is quite low.
On Jan 12, 2011, at 1:11 PM, Micah Carrick wrote: > I've got my site's authentication working with and email and password > only--no username (thanks to Shawn Milochik for helping me with that). > However, I still need to put in a username to make the User model happy. I > was hoping to have "user" as a prefix and then some unique number. > > I cannot simply copy the email to the username because the username must be > less than 30 characters and, after looking into my database, many email > addresses go over that. > I cannot generate a random number because there could be a collision. > I cannot use uuid4().hex because that's 32 characters... I need <30. > I cannot use User.objects.count() because that could result in a collision if > 2 users register at the same time. > > Thoughts? > > > > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.