btw... using 0.96 here...
On Jan 20, 9:27 am, sico <[email protected]> wrote:
> Hi,
>
> I'm filtering a model on some criteria... and based on the resultset I
> want to retrieve associated related models (all one-to-one
> relationships)
>
> Whats the most efficient way to do this without resorting to custom
> SQL?
>
> this is the best I can come up with:
>
> obj1s = MyModel1.filter(blah_blah=blah)
>
> data = []
> for obj1 in obj1s:
> obj2 = MyModel2.get(pk=obj.pk)
> obj3 = MyModel3.get(pk=obj.pk)
> data.append({'obj1':obj1,
> 'obj2':obj2,
> 'obj3':obj3,
> })
> return data
>
> I haven't checked but assuming this is going to execute 2 sql commands
> for each row returned by the first query.... not good!!
> Is there a way to tell django/python that I want to retrieve the
> related data from the other 2 models before looping through the
> queryset so it can figure out to do the necessary joins??
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---