There is probably an easy answer to this, but I have been scratching
my head for a while now: I have two models, Category and Program in a
one-to-many relationship. I want to list all categories, and all
programs within each category. I pass Category.objects.all() to the
view, and in the view I run a for loop over the categories, and a
second for loop over category.program_set.all in each category. The
question is, how can I sort the output in that second for-loop?

So, in code:
views.py:
def index(request):
    return render_to_response ( 'list.html', { 'categories':
Category.objects.select_related('program_set').all() } );

list.html:
{% for category in categories %}
    ...
    {{ category.name }}
    {% for program in category.program_set.all %}
        ...
        {{ program.name }}
        ...
    {% endfor %}
{% endfor %}

How can I make the inner loop produce sorted output?

Jon

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