I see nothing on this page that is in the slightest bit related to my question... Does anyone know if there is a way in the django orm to accomplish my query above?
Thanks. On Mar 13, 4:17 am, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Mar 12, 10:54 pm, jrs <j...@framemedia.com> wrote: > > > > > I'm trying, without a great deal of success, to perform a simpleself > >joinusing 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 > > LEFTJOINaccount parent ON > > account.id = parent.parent_account > > > This seems pretty basic, but I can't find any way to do it. > > > Thanks > > Accessing aselfjoinis 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.