On Thu, Jan 14, 2010 at 2:45 PM, nameless <xsatelli...@gmail.com> wrote:
>
>
> I want username field is automatically filled with this value:
>
> username = str(n);
>
> where n is a number of 10 digits ( autoincremented or random ).
>
> .
>
> I tried to add this in save method:
>
> username = str(random.randint(1000000000,9999999999))
>
> but there is a collision problem when n is the same for 2 users
> ( although rare initially ).
>
> .
>
> How do I do this ?
>
> Thanks ^_^
>

Use a version 4 UUID instead. If you generate 1 billion version 4
UUIDs a second for 100 years, you have ~ 50% chance of a collision.
They are also built in to later versions of python (2.5+):

>>> import uuid
>>> print uuid.uuid4()
92d6a4f4-918d-4a9b-8251-3150c88c62e7


Cheers

Tom
-- 
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.


Reply via email to