Re: Digest for django-developers@googlegroups.com - 2 updates in 1 topic

2022-01-27 Thread Ramez Ashraf
I almost never use `id` and always use `pk`.. at least whenever possible.
It gives me more freedom and sets a normalisation to code logic.
Very *very* useful 

On Fri, 28 Jan 2022, 05:40 ,  wrote:

> django-developers@googlegroups.com
> 
>  Google
> Groups
> 
> 
> Topic digest
> View all topics
> 
>
>- Deprecation of using pk in public ORM API
><#m_-3825817018666023648_group_thread_0> - 2 Updates
>
> Deprecation of using pk in public ORM API
> 
> Albert : 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" : 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
> Back to top <#m_-3825817018666023648_digest_top>
> 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-developers+unsubscr...@googlegroups.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/CAPtjUtgRSSWJzp1oxr5GWYCd3yzm0vZq-%3DXV198e_9Rujyg2aQ%40mail.gmail.com.


Re: Deprecation of using pk in public ORM API

2022-01-27 Thread Curtis Maloney
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.


Deprecation of using pk in public ORM API

2022-01-27 Thread Albert


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

-- 
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/degsdbrykkgpmlzcetdx%40khjm.