小编Sco*_*ton的帖子

修改django-tables2中DateTimes的显示格式

我当前正在使用django-tables2显示我的模型的查询集。该模型的属性之一是精确到毫秒的DateTimeField,该时间被截断到表中的分钟。

我以前用HTML手动实现了一个简单的表,没有任何问题。我的DateTimeFields遵循我的设置中应用的DATETIME_FORMAT:

settings.py

DATETIME_FORMAT = 'Y N j, H:i:s.u'
Run Code Online (Sandbox Code Playgroud)

自从我开始使用django-tables2以来,就出现了问题。有什么方法可以修改其显示DateTimeFields的方式或使其遵循我指定的DATETIME_FORMAT?我需要保留排序功能,因此无法转换为字符串。

我正在使用render_table显示我的表。以下是我的表类:

class ModelTable(tables.Table):
    class Meta:
        model = Measurement
        sequence = ('date_time', 'latitude', 'longitude',
                    'depth', 'soundvel', 'instrument')
Run Code Online (Sandbox Code Playgroud)

html python django django-tables2

4
推荐指数
2
解决办法
2248
查看次数

标签 统计

django ×1

django-tables2 ×1

html ×1

python ×1