views:

24

answers:

1

Here's a common situation that I have and wish to avoid creating tedious loops and fiddling with html tables:

I have a model Movie, which is has fkeys to Director and to Genre.

How can I elegantly render a simple data table that has on one axis the different Directors, on another axis the different Genres, and inside each cell the count of the movies filtered by the respective Director and Genre?

Thanks!

A: 

Create a custom template tag with syntax like:

{% datatable movie.director movie.genre %}

Where the first argument is the X axis, the second argument is the Y axis.

This way you're not trying to build the table using the limited template syntax.

I'd have the template tag not include the < table> tags, so that you can specify the table id and class(es) in the tempate.

Chris Lawlor