Thanks so much both of you, totally works and makes sense.  I used
Joseph's version because of the commas, but they both helped me
understand what was happening.
I notice that it seems to be ok to put the if statement on one line:

{% if filmmakers|length > 2 and not forloop.first %}, {% endif %}

is that generally ok, or do I want to indent everything and balance
the if/endif statements?

Thanks again,
Wendy

On Aug 11, 3:18 pm, Joseph Spiros <joseph.spi...@ithinksw.com> wrote:
> You'll want to loop through the objects and print the appropriate
> property of the objects that consists of just the name. Here's some
> template code that does that, and also separates with commas and "and",
> using a serial comma (aka Oxford comma).
>
> (This assumes that your Filmmaker model has a "name" property/field)
>
> {% with film.filmmakers.all as filmmakers %}{% for filmmaker in
> filmmakers %}{% if filmmakers|length > 2 and not forloop.first %}, {%
> endif %}{% if forloop.last and not forloop.first %} and {% endif %}{{
> filmmaker.name }}{% endfor %}
>
> Hope that helps!
>
> On 8/11/10 3:53 PM, Wendy wrote:
>
>
>
> > Hello,
> > I'm just getting started, and I'm returning a many to many object in
> > my template:
>
> > p>{{ film.filmmakers.all }}
>
> > So it's displaying the list:
>
> > [<Filmmaker: John Smith>, <Filmmaker: Suzie Brown>]
>
> > Can anyone tell me how to return just a string of the names?
> > I'm still getting acclimated to python syntax.
>
> > Actually in a perfect world, it would be great to concatenate the
> > names, and add an 'and' b4 the last one, I imagine this is done
> > frequently?
>
> > Thanks,
> > Wendy
>
> --
> Joseph Spiros
> iThink Software
> joseph.spi...@ithinksw.com
> +1 (440) 707-6855

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

Reply via email to