Re: Primary Key AutoField -> UUID Field
> On 20201115, at 09:47, Tim Graham wrote: > > Hi Brian, There are existing threads about that (try searching the archives > for 'default pk' to find some of them). Here's a PR that adds the setting you > described: https://github.com/django/django/pull/13179. Perhaps you would > like to try it out and see if it meets your needs. Agree - there are aspects of a UUID that avoid collisions with a far lesser probability than an arbitrary random value. I use this: from django.db import models import uuid class SomeModel(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) ... As already mentioned, using abstract models for this is also useful, helps with DRY. /d -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/38A8AB58-9299-48D0-8F50-50778486C822%40gmail.com.
Re: Primary Key AutoField -> UUID Field
Hi Brian, There are existing threads about that (try searching the archives for 'default pk' to find some of them). Here's a PR that adds the setting you described: https://github.com/django/django/pull/13179. Perhaps you would like to try it out and see if it meets your needs. On Saturday, November 14, 2020 at 11:32:38 AM UTC-5 brianrc...@gmail.com wrote: > Feature Request: > > I like to use the UUIDField as the primary key in my models, and I think > it would be nice to have django expose a setting in the settings.py to > override the default primary key on models. > > Currently, if I don’t specify a field as the primary key, Django > automatically uses an AutoField (auto-incrementing integer). I’d like to be > able to automatically use a UUID field, but then still be overridden in a > specific model if I specify a different primary key. > > Brian Carter > brianrc...@gmail.com -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/2cd6c330-0439-4ee7-88f5-b2ac708c78e0n%40googlegroups.com.
Re: Primary Key AutoField -> UUID Field
Uri, I would definitely suggest using an actual UUID rather than rolling your own ad-hoc UUID implementation, even if your database does not support a native UUID type. Brian, there is some work ongoing that should make this possible. We will add a setting to control the type of the auto-created primary key type. Initially it will be restricted to AutoField subclasses only, but the intent is to make UUIDFields work with this as well. The first bit of work is here: https://github.com/django/django/pull/13179 Tom > On 14 Nov 2020, at 16:54, אורי wrote: > > > Hi Brian, > > In Speedy Net we use a randomly generated string of digits, either 15 digits > or 20 digits, as a primary key in all our models. We never use > auto-incrementing integers as primary keys. You can take a look at our > implementation, especially class BaseModel which is the base class for all > our models, and class TimeStampedModel (most of our models inherit from > TimeStampedModel): > > https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/models.py > > We also defined managers with querysets in which bulk_create() and delete() > are disabled. > > Uri Rodberg, Speedy Net. > אורי > u...@speedy.net > > >> On Sat, Nov 14, 2020 at 6:32 PM Brian Carter >> wrote: >> Feature Request: >> >> I like to use the UUIDField as the primary key in my models, and I think it >> would be nice to have django expose a setting in the settings.py to override >> the default primary key on models. >> >> Currently, if I don’t specify a field as the primary key, Django >> automatically uses an AutoField (auto-incrementing integer). I’d like to be >> able to automatically use a UUID field, but then still be overridden in a >> specific model if I specify a different primary key. >> >> Brian Carter >> brianrcarte...@gmail.com >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django developers (Contributions to Django itself)" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-developers+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/EAF4690E-C862-4C68-A7DD-C2979F19BC3C%40gmail.com. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/CABD5YeFqeRfd6%2BMuMdzsagvjKdNu-iEDND-omuePX9TEw9TGTw%40mail.gmail.com. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/833A8A9F-14A2-4C37-8780-778F983C4B9D%40tomforb.es.
Re: Primary Key AutoField -> UUID Field
Hi Brian, In Speedy Net we use a randomly generated string of digits, either 15 digits or 20 digits, as a primary key in all our models. We never use auto-incrementing integers as primary keys. You can take a look at our implementation, especially class *BaseModel* which is the base class for all our models, and class *TimeStampedModel *(most of our models inherit from *TimeStampedModel*): https://github.com/speedy-net/speedy-net/blob/master/speedy/core/base/models.py We also defined managers with querysets in which *bulk_create()* and *delete()* are disabled. Uri Rodberg, Speedy Net. אורי u...@speedy.net On Sat, Nov 14, 2020 at 6:32 PM Brian Carter wrote: > Feature Request: > > I like to use the UUIDField as the primary key in my models, and I think > it would be nice to have django expose a setting in the settings.py to > override the default primary key on models. > > Currently, if I don’t specify a field as the primary key, Django > automatically uses an AutoField (auto-incrementing integer). I’d like to be > able to automatically use a UUID field, but then still be overridden in a > specific model if I specify a different primary key. > > Brian Carter > brianrcarte...@gmail.com > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/EAF4690E-C862-4C68-A7DD-C2979F19BC3C%40gmail.com > . > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CABD5YeFqeRfd6%2BMuMdzsagvjKdNu-iEDND-omuePX9TEw9TGTw%40mail.gmail.com.
Primary Key AutoField -> UUID Field
Feature Request: I like to use the UUIDField as the primary key in my models, and I think it would be nice to have django expose a setting in the settings.py to override the default primary key on models. Currently, if I don’t specify a field as the primary key, Django automatically uses an AutoField (auto-incrementing integer). I’d like to be able to automatically use a UUID field, but then still be overridden in a specific model if I specify a different primary key. Brian Carter brianrcarte...@gmail.com -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/EAF4690E-C862-4C68-A7DD-C2979F19BC3C%40gmail.com.