Hello Mike, On Wed, 26 Jan 2022, at 20:46, Albert wrote: > > Hello all, > > I would like to know your opinion about deprecation of using "pk" > alias in filters and other places of public ORM API. > I use Django long time and never use "pk" because in my opinion > it is misleading. > I mean, instead: > Car.objects.filter(pk=1) > I use > Car.objects.filter(id=1) > Insted car.pk I use car.id
AIUI the purpose of the `pk` alias is you can't assume the primary key will always be named `id`. Knowing you can always refer to `pk` allows more generic query construction. This is used, for example, in the generic views. > > From SQL point of view it doesn't matter because it is always: > SELECT * FROM car WHERE id=1 > > It am not sure if using "pk" gives value to users. Field "pk" is not > defined by user. No, but the model's primary key field might be, which is the point. -- Curtis -- 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/12cfc479-a288-4a3c-8cc7-bf47fd36db7a%40www.fastmail.com.