简体   繁体   English

人性化django-tables2输出?

[英]Humanizing django-tables2 output?

Here's a hack I'm currently using: 这是我正在使用的黑客攻击:

class ProductMaxIPPortEldCountMonthlyTable(tables.Table):                      
    ip_count = tables.TemplateColumn('{% load humanize %}{{ record.ip_count|intcomma }} ')

I'm using django.contrib.humanize . 我正在使用django.contrib.humanize Is there a cleaner way to achieve this effect? 是否有更清洁的方法来实现这种效果?

You can import the intcomma template filter, and define a custom render method for the column that uses it. 您可以导入intcomma模板过滤器,并为使用它的列定义自定义呈现方法

from django.contrib.humanize.templatetags.humanize import intcomma

class ProductMaxIPPortEldCountMonthlyTable(tables.Table):                      
    ip_count = tables.Column()

    def render_ip_count(self, value):
        return intcomma(value)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM