In the view the syntax is

world = Species.objects.all().select_related()
see the brackets after the all method.

only when you use the code in the template you don't put brackets for a
method/function.

On Fri, 2009-10-09 at 01:06 -0700, Eva Hamilton wrote:
> Oops, sorry, that's a typo in the post - but not present in the actual
> code.
> 
> It should have read...
> 
> world = Species.objects.all.select_related()
> family_list = [o.genus.family for o in world]
> 
> Or is there another missing ")" that I'm not seeing?
> 
> Thank you!
> 
> 
> On Oct 9, 5:18 pm, "Bogdan I. Bursuc" <bogdanbursu...@gmail.com>
> wrote:
> > You forgot a ")" sign. That's why syntax error.
> >
> > On Thu, 2009-10-08 at 23:48 -0700, Eva Hamilton wrote:
> > > >From the django documentation 
> > > >(here:http://www.djangoproject.com/documentation/models/select_related/)
> > > I obtained this bit of code for performing a select_related on a list
> > > of objects and producing a list of related objects...
> >
> > > >>> world = Species.objects.all().select_related()
> > > >>> [o.genus.family for o in world]
> > > [<Family: Drosophilidae>, <Family: Hominidae>, <Family: Fabaceae>,
> > > <Family: Amanitacae>]
> >
> > > It works perfectly in the python shell, but I'm wondering what the
> > > correct syntax would be to achieve the same result in a django view?
> > > ie. define a variable that will produce the list of related objects
> > > and can then be used in a template.
> >
> > > I've tried:
> >
> > > world = Species.objects.all(select_related()
> > > family_list = [o.genus.family for o in world]
> >
> > > but get a "syntax error" message.
> >
> > > Can anyone help? Thanks!
> > 


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to