Sequences are best solution for me but I don't know how to implement its in django+mysql. I tought also to use id as username but I don't know how do this :-\
Could you explain me how do pleaseeeeeee ? Thank you --------------- On Jan 14, 4:16 pm, Shawn Milochik <sh...@milochik.com> wrote: > There are a bunch of ways you can do it. As a previous poster said, you can > take 10 digits of the current timestamp. However, be wary of daylight saving > time changes (if you have them on your server), and the possibility of any > conflict if you change servers, have a backup server, or ever expand to > multiple servers for your application. > > A possibility, if you're open to alphanumeric strings, is a uuid, > specifically uuid4 or uuid1. Check out the documentation to see if they'd > work for you. If you don't care to necessarily limit it to 10 characters, and > you don't mind alpha-numeric characters, then just use a uuid4 and you're > done.http://docs.python.org/library/uuid.html > > Yet another possibility is to use the capability of your database to create > sequences. If you're using Postgres, it has a SEQUENCE which you can create, > and always ask it for the next one. You can start a sequence at any number > you like, in order to get the size you want. We do something similar for > generating customer numbers. We have a sequence, and we use it appended to a > static set of digits for the particular program the customer is in. So, for > example, all customers in program X would have a customer number of 10 digits > starting with '1001' and ending with an incremental number. There are ways to > do this with other databases. Worst-case you can create a table with an > auto-increment key and just use its primary key for your next digit. > > One more, but not last nor least, is to have your model generate the string > you want by one of the means above, or something completely different, then > override the save() of your model to check to ensure that this key doesn't > exist already. This is less than ideal, but maybe there's a case to be made > for it. Just throwing it in as an option. > > Shawn
-- 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.