【问题标题】:django-tables2 How to set Verbose name for _setdjango-tables2 如何为 _set 设置详细名称
【发布时间】:2019-06-18 10:13:07
【问题描述】:

我有一个值ccu_set.all.first.player_count

效果很好,但我想更改详细名称,以便在表格中不显示“ccu_set.all.first.player_count”。

但是当我这样做时:

ccu_set.all.first.player_count = tables.Column(verbose_name= 'CCU', default='')

它给出了以下错误:

NameError: 名称 'ccu_set' 未定义

【问题讨论】:

    标签: python django python-3.x django-tables2


    【解决方案1】:

    通过向模型添加@property 来修复它

    @property
        def latest_ccu(self):
            try:
                return self.ccu_set.first().player_count
            except:
                return None
    

    然后我就这样做了

    latest_ccu = tables.Column(verbose_name= 'CCU', default='')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 2012-12-18
      • 1970-01-01
      • 2020-06-26
      • 2011-11-17
      • 2018-09-13
      • 2022-10-06
      相关资源
      最近更新 更多