On Mar 12, 10:54 pm, jrs <j...@framemedia.com> wrote: > I'm trying, without a great deal of success, to perform a simple self > join using the django orm. I'm pretty sure the F() function is not > the answer. I believe this only allows you to compare two field > within the same model instance, not to compare fields within 2 > instances of the same model. I want to do this - > > Model- > > class Account(models.Model): > name = models.CharField(max_length=255) > parent_account = models.ForeignKey('self', default=None, > blank=True) > > SQL- > > SELECT account.*, parent.* > FROM account > LEFT JOIN account parent ON > account.id = parent.parent_account > > This seems pretty basic, but I can't find any way to do it. > > Thanks
Accessing a self join is no different from accessing any other related objects. Read this: http://docs.djangoproject.com/en/1.1/ref/models/relations/ It helps not to think in terms of SQL, but in terms of objects, when using the ORM. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.