- Deprecation of using pk in public ORM API - 2 Updates
Albert <al...@interia.eu>: Jan 26 10:46AM +0100
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
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.
But from our, django developers, point of view we need to do extra work to
support it.
I think that "pk" could be only a private attribute of a model
("_pk") and only for internal use or avoid using it at all.
I think it would give us more flexibility to develop/improve orm.
What do you think?
Regards,
Albert Defler
"Curtis Maloney" <cur...@tinbrain.net>: Jan 28 10:24AM +1100
Hello Mike,
On Wed, 26 Jan 2022, at 20:46, Albert wrote:
> 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.
> 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 digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to django-develop...@googlegroups.com.