The Django db-api handles JOINs for you. It abstracts them into
"forward", "backward" and "many-to-many" relationships (as documented
on the page I linked before).

Spend some time on the command line playing with these relationships
and you'll see how you can navigate around your models through foreign
keys and such.

Also, if you need quicker answers, join #django on irc.freenode.net
and paste your models at dpaste.com. There's always really bright,
helpful people hanging around on there.

Grant

On Jul 19, 1:49 pm, Joshua <[EMAIL PROTECTED]> wrote:
> Maybe I should have titled this how do I create a left join in Django
> syntax or with the Django db-API
>
> All the examples in the documentation let you retrieve the related
> object ONLY if you have ONE related object retrieved.
>
> On Jul 19, 2:18 pm, Joshua <[EMAIL PROTECTED]> wrote:
>
> > Thank you for your response
>
> > I'm not familiar with the context object - I'll have to do some
> > research.
>
> > I have this working
>
> > portfolioPage =
> > client.objects.filter(project_portfolio__project_display_bit = True)
>
> > It's returning the clients data - just not the data for the
> > project_portfolio (it's not joining)?
>
> > On Jul 19, 2:08 pm, gkelly <[EMAIL PROTECTED]> wrote:
>
> > > I believe in your template you should be able to do something like:
>
> > > {% for p in project_portfolio_list %}
> > >   {{ p.project_name_char }} {{ p.project_client.client_name_char }}
> > > {% endfor %}
>
> > > If you had a view with:
>
> > > context['project_portfolio_list'] = project_portfolio.objects.all()
>
> > > You'll also want to be familiar with this portion of the 
> > > docs:http://www.djangoproject.com/documentation/db-api/#related-objects
>
> > > Hope that helps,
> > > Grant
>
> > > On Jul 19, 11:02 am, Joshua <[EMAIL PROTECTED]> wrote:
>
> > > > I've tried to search for a solution to this problem for the last 2
> > > > hours and I can't seem to figure it out.
>
> > > > I basically want to return a joined table from a queryset - formatted
> > > > for my template.
>
> > > > I can't seem to figure out how to do this with the Django database
> > > > API.
>
> > > > With SQL a join query works out to:
>
> > > > '''
> > > > select project_portfolio.*, client.*
> > > > from project_portfolio left join client
> > > > on project_portfolio.id = client.id
> > > > '''
> > > > with the following simplified models:
>
> > > > class project_portfolio(models.Model):
> > > >     project_name_char = models.CharField()
> > > >     project_client = models.ForeignKey(client)
>
> > > > class client(models.Model):
> > > >     client_name_char = models.CharField
>
> > > > The challenge here seems to be that I have to return MULTIPLE
> > > > project_portfolio objects and THEN get the "client" data - because NOT
> > > > all "clients" have "project_portfolio(s)"
>
> > > > Thank you in advance for any help - Josh


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
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