On Mar 23, 9:26 pm, "makebelieve" <[EMAIL PROTECTED]> wrote:
> Ok, from a previous post I've found that the best way to list items by
> a category is to use _set:
>
> {% for c in categories %}
>     <h2>{{ c }}</h2>
>         {% for i in c.item_set.all %}
>             <p>{{ v }}</p>
>         {% endfor %}
> {% endfor %}
>
> However, what if I want to limit the items based upon one of their
> attributes? For example I want the user to be able to filter the items
> by their state of origin, and also still want them to list by
> category. I can't use item_set.filter() in a template, nor do I want
> to.  That kind of logic should be in the view, but how?
>

Actually, this kind of logic could be in a custom tag. Consider the
following:

{% for c in categories %}
    <h2>{{ c }}</h2>
        {% my_custom_tag c 'NY' %}
        {% for i in my_custom_filtered_queryset %}
                <p>{{ v }}</p>
        {% endfor %}
{% endfor %}

Then, follow the write up on how to set context variables here:
http://www.djangoproject.com/documentation/templates_python/#setting-a-variable-in-the-context

You will also need to resolve the category object c, inside your
custom tag's rendering class. Follow this write up to achieve this:
http://www.djangoproject.com/documentation/templates_python/#passing-template-variables-to-the-tag

Basically, your custom tag will end up setting a context variable
called, say  my_custom_filtered_queryset which is programmed in the
custom tag renderer class to be the query set you need to filter 'c'
by state ('NY', in the above example.)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to