`prefetch_related` for non-homogenous data and "weak" lookups through GFKs

80 views
Skip to first unread message

andrew.pashkin

unread,
Feb 8, 2014, 3:14:32 PM2/8/14
to django-d...@googlegroups.com
With GenericForeignKey functionality, it is possible to refer to arbitrary model. Let's ay we have Like model, which is naturally may refer to many types of data (blogposts, users, photos, comments, etc). And so it is desireable to be able to perform such lookups:

Like.objects.prefetch_related('content_object__followers', 'content_object__people_on_photo')

where followers is the field of User model and people_on_photo the field of Photo model.

Currently .prefetch_related will raise an error like

Cannot find field `followers` on Photo object.

because currently it is assumed that lookups are 'strict', and data for each lookup is homogenous (stealed the word form comment in sources :).
So I think it would be nice to implement feature for non-strict lookups in addition to #17001‎.

Andrew Pashkin

unread,
Feb 21, 2014, 7:12:55 AM2/21/14
to django-d...@googlegroups.com
Ive made workaround for this case as external app.
Reply all
Reply to author
Forward
0 new messages