I've got a view that returns a generic list. It contains the following
fields:
school, wins, losses, pf, pa, rating

I want to add a field called rank that assigns the values 1 through
whatever for each of the records returned. Is this possible using the
templating engine or do I have to write pure python code to achieve
this?

Here's my views.py:

def rankings_by_conference(request, conference):
    try:
        conference = Conference.objects.get(slug__iexact=conference)
    except Conference.DoesNotExist:
        raise Http404

    return list_detail.object_list(
        request,
        queryset = SchoolData.objects.filter
(school_season__conference=conference).order_by('-rating'),
        template_name = "college/rankings_by_conference.html",
        template_object_name = "rankings",
        extra_context = {"conference": conference}
    )

And here's my template:
{% extends "base.html" %}

{% block title %}Rankings by Conference{% endblock %}

{% block content %}

<h2>2009 {{ conference.conf_name }} Rankings</h2>

<table>
        <thead>
                <tr>
                        <th>Rank</th>
                        <th>School</th>
                        <th>Wins</th>
                        <th>Losses</th>
                        <th>Ties</th>
                        <th>PF</th>
                        <th>PA</th>
                        <th>Rating</th>
                        <th>Schedule Strength</th>
        </thead>
        <tbody>
        {% for ranking in rankings_list %}
                <tr>
                        <td>{{ rankings.counter }}</td>
                        <td>{{ ranking.school_season.school.short_name }}</td>
                        <td>{{ ranking.wins }}</td>
                        <td>{{ ranking.losses }}</td>
                        <td>{{ ranking.ties }}</td>
                        <td>{{ ranking.pf }}</td>
                        <td>{{ ranking.pa }}</td>
                        <td>{{ ranking.rating }}</td>
                        <td>{{ ranking.schedule_strength }}</td>
                </tr>
        {% endfor %}
        </tbody>
</table>

{% endblock %}

As you can see, I've tried using the counter variable but its not
returning anything.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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