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 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 that row. When I run test = > content.objects.select_related().get(pk=3) and if I knew how many > parents there are I can get them all using test.parent then > test.parent.parent... etc.. But I need to be able to iterate though and > get the full list. Does anyone how I can do that? > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---