thanks for your response. well, i am trying to get a list of dependents of a given object in a single query. i want to be able to retrieve the dependents by key (the object name) from this list.
i do not see any way of doing this but getting the query set and converting it to a dictionary manually: d = dict() for x in AB.objects.select_related().filter(aa__name = 'aa') : y = x.bb d[y.name] = y i was trying to avoid this extra list traversal... konstantin On Mar 9, 11:28 am, Atilla <[EMAIL PROTECTED]> wrote: > On 09/03/07, akonsu <[EMAIL PROTECTED]> wrote: > > > > > > > > > hello, > > > the code below generates two queries to the database. is there a way > > to make it get all objects related to object 'aa' and then just look > > up the right one when get() is called? > > > thanks > > konstantin > > > class AA(models.Model) : > > name = models.SlugField() > > > class BB(models.Model) : > > name = models.SlugField() > > > class AB(models.Model) : > > aa = models.ForeignKey(AA) > > bb = models.ForeignKey(BB) > > > r = AB.objects.select_related().filter(aa__name = 'aa') > > > l = list(r) # this evaluates 'r' but the statements below hit the > > database anyway... > > > print r.get(bb__name = 'bb1') > > print r.get(bb__name = 'bb2') > > Calling .get() will always execute a query to retrieve you 1 specific > item. Perhaps you need to rethink the way you're trying to fetch and > use your data. What exactly are you trying to accomplish here ?- Hide quoted > text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---