Design Decision: GFK Reverse Lookups

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Design Decision: GFK Reverse Lookups

Carlton Gibson-3
Hi All.

https://github.com/django/django/pull/9748 adds the ability to perform simple queries on a generic foreign key: 

    TaggedItem.objects.filter(content_object=object_instance)

You still can't do anything more complex, such as:

    TaggedItem.objects.get(content_object__name='Diamond')

This is a long standing Someday/Maybe: https://code.djangoproject.com/ticket/3006



The patch seems more or less OK to me but I'm not sure if we shouldn't instead guide users firmly towards defining a GenericRelation. 

GenericRelation provides for the more powerful querying, and, this way, provides the one correct way™ to do things. 

I'm wondering what the correct view should be: whether we take this patch or close the issue as wontfix and solely recommend GenericRelation. 



Thanks for your input. 

Kind Regards,

Carlton

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/c81e6d2d-7254-4ad5-b8dd-c8c05726f55c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Design Decision: GFK Reverse Lookups

Tim Graham-2
I'd lean toward a wontfix. In particular, making changes in django/db/models/sql/query.py for a contrib app doesn't look like a good separation of concerns. Is there a downside to the alternative of adding the GenericRelation?

On Tuesday, April 10, 2018 at 3:38:53 AM UTC-4, Carlton Gibson wrote:
Hi All.

<a href="https://github.com/django/django/pull/9748" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fpull%2F9748\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNElfxStbvpQX9YnJtrJs37pwkAaRA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fdjango%2Fdjango%2Fpull%2F9748\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNElfxStbvpQX9YnJtrJs37pwkAaRA&#39;;return true;">https://github.com/django/django/pull/9748 adds the ability to perform simple queries on a generic foreign key: 

    TaggedItem.objects.filter(content_object=object_instance)

You still can't do anything more complex, such as:

    TaggedItem.objects.get(content_object__name='Diamond')

This is a long standing Someday/Maybe: <a href="https://code.djangoproject.com/ticket/3006" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F3006\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEUkkpBVx2RBG1PfKqQzrsQdqhOdw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fcode.djangoproject.com%2Fticket%2F3006\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEUkkpBVx2RBG1PfKqQzrsQdqhOdw&#39;;return true;">https://code.djangoproject.com/ticket/3006



The patch seems more or less OK to me but I'm not sure if we shouldn't instead guide users firmly towards defining a GenericRelation. 

GenericRelation provides for the more powerful querying, and, this way, provides the one correct way™ to do things. 

I'm wondering what the correct view should be: whether we take this patch or close the issue as wontfix and solely recommend GenericRelation. 



Thanks for your input. 

Kind Regards,

Carlton

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/acf29f15-a3db-425f-b628-71e87e5d3725%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Design Decision: GFK Reverse Lookups

Adam Johnson-2
I agree, adding more functionality to the ORM for this one limited use case doesn't seem worth it, especially given GenericRelation's existence.

On 18 April 2018 at 17:10, Tim Graham <[hidden email]> wrote:
I'd lean toward a wontfix. In particular, making changes in django/db/models/sql/query.py for a contrib app doesn't look like a good separation of concerns. Is there a downside to the alternative of adding the GenericRelation?

On Tuesday, April 10, 2018 at 3:38:53 AM UTC-4, Carlton Gibson wrote:
Hi All.

https://github.com/django/django/pull/9748 adds the ability to perform simple queries on a generic foreign key: 

    TaggedItem.objects.filter(content_object=object_instance)

You still can't do anything more complex, such as:

    TaggedItem.objects.get(content_object__name='Diamond')

This is a long standing Someday/Maybe: https://code.djangoproject.com/ticket/3006



The patch seems more or less OK to me but I'm not sure if we shouldn't instead guide users firmly towards defining a GenericRelation. 

GenericRelation provides for the more powerful querying, and, this way, provides the one correct way™ to do things. 

I'm wondering what the correct view should be: whether we take this patch or close the issue as wontfix and solely recommend GenericRelation. 



Thanks for your input. 

Kind Regards,

Carlton

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/acf29f15-a3db-425f-b628-71e87e5d3725%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Adam

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM2J5zDz0Sr-TKp6uQpn7LkDYAAm28C83EK6kkW%3D0KZ0_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.