It's a one-to-one relationship between queryset's content and
my_list's content.

in my view
========
return object_list( request,
                                 queryset=qs,
                                 template_name='my_template.html',
                                 extra_context={ 'my_list':
my_list, ... }, )

template(not work)
=================
{% for object in object_list %}
    {{ object.xx }}: {{ my_list.forloop.counter0 }}
{% endfor %}

I have other solution:
1. template tag
2.
[view]
    zipped = []
    for qs_obj in qs:
      list_value = find the list_value for qs_obj
      zipped.append( ( qs_obj, list_value) ) # add them as a tuple

[template]
{% for qs_obj, list_value in products %}
  {{qs_obj}}:  {{list_value}}
{% endfor %}

I wonder If django has a build-in way to do this. (It seems that
django has no build-in way...)
Thank you.

On Sep 14, 4:03 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 13 sep, 18:20, "David.D" <dengyuanzh...@gmail.com> wrote:
>
> > In my template:
>
> > This is ok:
> > {{ my_list.2 }}
>
> > But it doesn't work:
> > {{ my_list.index }}
>
> > index is a context variable (index=2)
>
> This first looks up my_list for an attribute named "index" - which
> resolves to the "index" method of the list class if my_list is really
> a list - then try to do a dict lookup (ie: my_list["index"]). So
> technically speaking, it does "work" - in that does what the fine
> manual says it should do !-)
>
> Now, what's your use case exactly ? You don't need indexed access to
> iterate over a sequence, and if you know both my_list and index in
> your view (or templatetag or whatever), then you can just pass the
> appropriate value in your context from the view code itself.

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