Re: select_related() with the ForeignKey in the same table

2006-12-18 Thread John Lenton
On 12/15/06, leanmeandonothingmachine <[EMAIL PROTECTED]> wrote: > > I have a model where the foreign key refers to it self. > parent = models.ForeignKey('self', core=True, null=True, blank=True) > > What i want to do is to be able to run a query with select_related and > get all the parents of th

Re: select_related() with the ForeignKey in the same table

2006-12-18 Thread Aidas Bendoraitis
You can still get all the parents using a cycle: current = Content.objects.select_related().get(pk=3) while current: # do something with the current object, i.e. write to a list # ... current = current.parent # get the parent of the current Good luck! Aidas Bendoraitis aka Archatas