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
)
--
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...@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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAYykEHF8qxAEc%2BPh71ue%3DKLzpT3P5MuE2Dw58gG2HmUEw%40mail.gmail.com.
--
--
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7EoAYykEHF8qxAEc%2BPh71ue%3DKLzpT3P5MuE2Dw58gG2HmUEw%40mail.gmail.com.
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.אורי
On Fri, Oct 4, 2019 at 5:53 PM yashwanth .k <kyashw...@gmail.com> 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.