On 8/9/05, xtian <[EMAIL PROTECTED]> wrote:
> {% for choice in poll.get_choice_list(order_by=['-votes']) %}
>
> doesn't work - obviously the for tag isn't expecting arbitrary
> expressions, despite looking like the Python for loop.
>
> Is there a better way to handle this kind of thing? Have you guys
> found that you tend not to need this capability in the template
> language in practice? Is this just a case where you wouldn't use a
> generic view for the results display?
You guessed right: We've found that we don't need this capability in
the template language in practice. Generally we handle this specific
problem by using default ordering where possible. If you want the
following template code to order descending by number of votes...
{% for choice in poll.get_choice_list %}
...just set "ordering = ['-votes']" on your Choice model.
poll.get_choice_list() will use whatever the default ordering is for
Choice objects.
Of course, as you point out, you could write your own view, rather
than using a generic view, if you need more fine-grained control. Both
solutions are pretty easy and don't require much code. :)
Adrian