Am Montag, 8. Oktober 2007 15:13 schrieb [EMAIL PROTECTED]:
> In my model class I have:
>
> class Company(models.Model):
>     company_id = models.AutoField(primary_key=True)
>     parent_company = models.ForeignKey("self",null=True)
>     .
>     .
>
>
> How would I query to get back all children companies, as well as all
> of their children companies, and their children companies, etc,
> without writing a nested loop to do so?
>

My models has a method like this:

    def parents(self):
        iloop=0
        parent=self.parent
        parents=[]
        while parent:
            iloop+=1
            assert iloop<1000, "Endlosschleife"
            parents.append(parent)
            parent=parent.parent
        return parents

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to