Re: How to generate a unique 9 digit random id for every registered user?

2019-10-05 Thread yashwanth .k
Hello Uri, 
Thank you soo much,
your work made my work easy.
Thank you!

On Saturday, October 5, 2019 at 9:41:22 AM UTC+5:30, Uri wrote:
>
> Hi,
>
> In Speedy Net we generate a unique random ID with 15 digits and this is 
> used as the table's primary key. We don't use the DB's auto-generated ID.
>
> The first digit of the random ID we generate is never zero.
>
> https://github.com/speedy-net/speedy-net 
>
> https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/utils.py
>  
>
> https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/models.py#L33-L48
>  
>
> https://github.com/speedy-net/speedy-net/blob/master/speedy/core/accounts/models.py
>  
> אורי
> u...@speedy.net 
>
>
> On Fri, Oct 4, 2019 at 5:53 PM yashwanth .k  > wrote:
>
>> Hello,
>>
>> My model consists of user details such as username and his id which is 
>> auto-generated by DB(indexing). 
>> Apart from this, I need to assign a random unique 9 digit number for 
>> every user.
>> The reason for assigning a random number to a registered user is to 
>> search a particular user using his permanent random id which we have 
>> generated.
>>
>> Solutions with the model description will be very helpful.
>>
>>
>> Thank you!
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/93fa36de-feac-4120-b441-48e39b039eb4%40googlegroups.com.


Re: How to generate a unique 9 digit random id for every registered user?

2019-10-04 Thread yashwanth .k
Hello Aldian Fazrihady,
Your code is working,
How to link this code to my user so that when I search the code I should
grab user profile.
Thank you so much for sharing the approach.

On Fri, Oct 4, 2019 at 8:41 PM Aldian Fazrihady  wrote:

> import random
> import string
>
> from django.db import models
>
>
> def generate_random_code():
> return ''.join(random.choices(string.ascii_uppercase + string.digits, 
> k=9))
>
>
> class MyModel(models.Model):
> code = models.CharField(
> max_length=9, default=generate_random_code, db_index=True
> )
>
> Hi, please try the code above.
>
> On Fri, Oct 4, 2019 at 9:53 PM yashwanth .k 
> wrote:
>
>> Hello,
>>
>> My model consists of user details such as username and his id which is
>> auto-generated by DB(indexing).
>> Apart from this, I need to assign a random unique 9 digit number for
>> every user.
>> The reason for assigning a random number to a registered user is to
>> search a particular user using his permanent random id which we have
>> generated.
>>
>> Solutions with the model description will be very helpful.
>>
>>
>> Thank you!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Regards,
>
> Aldian Fazrihady
> http://aldianfazrihady.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAN7EoAYykEHF8qxAEc%2BPh71ue%3DKLzpT3P5MuE2Dw58gG2HmUEw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALgTQA%2B2qSnsWRqNXaXpSzUpx3w_VQogfGbKRWVX4OX3mgVVsQ%40mail.gmail.com.


Re: How to generate a unique 9 digit random id for every registered user?

2019-10-04 Thread אורי
Hi,

In Speedy Net we generate a unique random ID with 15 digits and this is
used as the table's primary key. We don't use the DB's auto-generated ID.

The first digit of the random ID we generate is never zero.

https://github.com/speedy-net/speedy-net
https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/utils.py

https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/models.py#L33-L48

https://github.com/speedy-net/speedy-net/blob/master/speedy/core/accounts/models.py

אורי
u...@speedy.net


On Fri, Oct 4, 2019 at 5:53 PM yashwanth .k  wrote:

> Hello,
>
> My model consists of user details such as username and his id which is
> auto-generated by DB(indexing).
> Apart from this, I need to assign a random unique 9 digit number for every
> user.
> The reason for assigning a random number to a registered user is to search
> a particular user using his permanent random id which we have generated.
>
> Solutions with the model description will be very helpful.
>
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeF5KhEhDGJ%2B1i3hjOR21_Mw%2B%3Dy2D-a3K9eaX_rMFKE3oQ%40mail.gmail.com.


Re: How to generate a unique 9 digit random id for every registered user?

2019-10-04 Thread Suraj Thapa FC
Use uuid

On Fri, 4 Oct, 2019, 8:23 PM yashwanth .k,  wrote:

> Hello,
>
> My model consists of user details such as username and his id which is
> auto-generated by DB(indexing).
> Apart from this, I need to assign a random unique 9 digit number for every
> user.
> The reason for assigning a random number to a registered user is to search
> a particular user using his permanent random id which we have generated.
>
> Solutions with the model description will be very helpful.
>
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcGEKwpduX3uHifHaSXEORFq%3DvjwrWUe69O1CKVsMNXCQA%40mail.gmail.com.


Re: How to generate a unique 9 digit random id for every registered user?

2019-10-04 Thread Jani Tiainen
Note that above solution doesn't guarantee unique id. As it is a problem of
any pseudorandom generator.

So it is possible (but unlikely) that insertion fails.

pe 4. lokak. 2019 klo 18.12 Aldian Fazrihady  kirjoitti:

> import random
> import string
>
> from django.db import models
>
>
> def generate_random_code():
> return ''.join(random.choices(string.ascii_uppercase + string.digits, 
> k=9))
>
>
> class MyModel(models.Model):
> code = models.CharField(
> max_length=9, default=generate_random_code, db_index=True
> )
>
> Hi, please try the code above.
>
> On Fri, Oct 4, 2019 at 9:53 PM yashwanth .k 
> wrote:
>
>> Hello,
>>
>> My model consists of user details such as username and his id which is
>> auto-generated by DB(indexing).
>> Apart from this, I need to assign a random unique 9 digit number for
>> every user.
>> The reason for assigning a random number to a registered user is to
>> search a particular user using his permanent random id which we have
>> generated.
>>
>> Solutions with the model description will be very helpful.
>>
>>
>> Thank you!
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Regards,
>
> Aldian Fazrihady
> http://aldianfazrihady.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAN7EoAYykEHF8qxAEc%2BPh71ue%3DKLzpT3P5MuE2Dw58gG2HmUEw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91oc4scdb1Vd5W9_pifq128kE87PRJ-ac_oiQbCe3QEMi5w%40mail.gmail.com.


Re: How to generate a unique 9 digit random id for every registered user?

2019-10-04 Thread Aldian Fazrihady
import random
import string

from django.db import models


def generate_random_code():
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=9))


class MyModel(models.Model):
code = models.CharField(
max_length=9, default=generate_random_code, db_index=True
)

Hi, please try the code above.

On Fri, Oct 4, 2019 at 9:53 PM yashwanth .k  wrote:

> Hello,
>
> My model consists of user details such as username and his id which is
> auto-generated by DB(indexing).
> Apart from this, I need to assign a random unique 9 digit number for every
> user.
> The reason for assigning a random number to a registered user is to search
> a particular user using his permanent random id which we have generated.
>
> Solutions with the model description will be very helpful.
>
>
> Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com
> 
> .
>


-- 
Regards,

Aldian Fazrihady
http://aldianfazrihady.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7EoAYykEHF8qxAEc%2BPh71ue%3DKLzpT3P5MuE2Dw58gG2HmUEw%40mail.gmail.com.


How to generate a unique 9 digit random id for every registered user?

2019-10-04 Thread yashwanth .k
Hello,

My model consists of user details such as username and his id which is 
auto-generated by DB(indexing). 
Apart from this, I need to assign a random unique 9 digit number for every 
user.
The reason for assigning a random number to a registered user is to search 
a particular user using his permanent random id which we have generated.

Solutions with the model description will be very helpful.


Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8eb92ef2-ffe0-431d-b4aa-3d6c5a119c3f%40googlegroups.com.