Design Decision: GFK Reverse Lookups

99 views
Skip to first unread message

Carlton Gibson

unread,
Apr 10, 2018, 3:38:53 AM4/10/18
to Django developers (Contributions to Django itself)
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

Tim Graham

unread,
Apr 18, 2018, 12:10:04 PM4/18/18
to Django developers (Contributions to Django itself)
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?

Adam Johnson

unread,
Apr 18, 2018, 3:39:31 PM4/18/18
to django-d...@googlegroups.com
I agree, adding more functionality to the ORM for this one limited use case doesn't seem worth it, especially given GenericRelation's existence.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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
Reply all
Reply to author
Forward
0 new messages