开发者

How to elegantly create a datatable with Django?

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 Ge开发者_开发知识库nre?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜