Bruno, you were absolutely right - the "last" tag in my loop wasn't really
the last. I had this:

for tag in tags_list:
          tag.blogs_count = tag.blogpost_set.count()

So, each tag would get a blog count, and some tags had zero blogs. In the
template, I was only writing out those tags that had a blog count above
zero, yet the loop would iterate over the rest of the tags and not write
them out.

I did a small fix in my views as follows:

for tag in tags_list:
          tag.blogs_count = tag.blogpost_set.count()

          clean_tags = []
          for tag in tags_list:
               if tag.blogs_count != 0:
                    clean_tags.append(tag)

          tags_list = clean_tags

I am now passing a list of only those tags with a blog count greater than
nought.

Thanks!

On Fri, Nov 19, 2010 at 12:51 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

>
>
> On 19 nov, 11:09, Sithembewena Lloyd Dube <zebr...@gmail.com> wrote:
> > Hi everyone,
> >
> > I have a template where Django is spitting out blog tags followed by a
> ','
> > when the tag is not the final one in the loop.
> >
> > {% if not forloop.last %}, {% endif %}
> >
> > Strangely, I am still seeing tag1, tag2, tag3,
>
> This shouldn't happen, but since such an obvious bug would have been
> spotted long ago, I guess you do have an "empty" element (for whatever
> definition of "empty" apply here) at the end of your list or queryset.
> So better to first check your data...
>
>
>
>
>
>
>
> > --
> > Regards,
> > Sithembewena Lloyd Dubehttp://www.lloyddube.com
>
> --
> 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<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

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