Er, I forgot to add an {% endwith %} at the end. You don't HAVE to use
the with tag at all, but it can make things a bit easier.

On 8/11/10 6:18 PM, Joseph Spiros 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