2012-11-08 7 views
5

私のために私のテーブルを作成するのにdjango-tables2を使用しています。私は、いずれかの列の各セル()にテンプレートタグを適用する必要があります。 1つの列にテンプレートタグを適用するだけで、カスタムテーブルレイアウトを作成して作成することは、多大な努力のようです。 django-tables2でこれを行う方法はありますか?django-tables2を使用しているときに​​にテンプレートタグを適用できますか?

更新:

私が十分に探しているものは説明していないかもしれません。それがうまくいくとは思わない。

マイコード:

class CombineTable(tables.Table): 
    build_no = tables.LinkColumn('run', args=[A('release'), A('id')], verbose_name="Build") 
    flavor = tables.Column(verbose_name="Flavor") 
    pass_rate_pct = tables.Column(verbose_name="Image Pass Rate") 

Iは(pass_rate_pct内の各クラスにテンプレートタグ{{pass_rate_colorを}}使用する)pass_rate_color次いでpass_rate_pctの出力が何であるかに基づいて特定のスタイルを出力します。

答えて

1

django_tables2ができます。 django_tables2/templates/django_tables2/table.htmlのコピーをとり、名前を変更します。 table_pass_rate.htmlとライン29上のタグを入力:テーブルの使用を生成するときに今

{% pass_rate_color cell %} 

{% render_table table "table_pass_rate.html" %} 

tagsと詳細はtemplateためdjango_tables2コードを参照してください。

+0

これは私が行った方法ですが、そこではif文を実行して、特定の列でpass_rate_colorだけを実行する必要がありましたが、機能しました。ありがとう。 – cjohnston

0

Table.render_FOOメソッドをオーバーライドしてください。ここで、fooは列名 です。列値を引数として使用するカスタムテンプレートタグを作成したとします。例えば :あなたのテーブルを出力するための代替カスタムテンプレートを指定するため

import django_tables2 as tables 

class SimpleTable(tables.Table): 
    custom_row = tables.Column() 
    id = tables.Column() 
    age = tables.Column() 

    def render_custom_row(self, value): 
     return '{% pass_rate_color %s %}' % value 
+0

私は上記の私の質問を編集しました。カスタムテンプレートタグの作成に関する – cjohnston

+0

を参照してください。https://docs.djangoproject.com/en/dev/howto/custom-template-tags/ –

+0

templatetagは既に存在します。私はtables.pyを渡す方法を理解しようとしています。現在、実際にはtemplatetagの代わりにプレーンテキストとしてソースに表示されます。 – cjohnston

関連する問題