簡體   English   中英

Django Table2獲取值綁定列

[英]Django Table2 get value bound column

我很困惑,請告訴我如何在 Table.render_foo 方法中獲取另一個Term_Implementation字段的值?

Table.render_foo 方法

綁定列

BoundColumn-getitem

class EvensList(IncidentsTable, tables.Table):

    class Meta:
        model = AkpEvents
        
        sequence = ('Term_Implementation', 'Status')

    Term_Implementation = tables.DateColumn(empty_values=(),)

    Status = tables.Column(empty_values=(),)

   def render_Status(self, value, column, columns):
        if value == 'Выполнено':
            column.attrs = {'td': {'class': 'table-success'}}

        elif value == 'В работе':
            column.attrs = {'td': {'class': 'table-warning'}}

        elif columns['Term_Implementation'] <= date.today():
            column.attrs = {'td': {'class': 'table-danger'}}

        else:
            column.attrs = {'td': {'class': ''}}

        return value

為了解決這個問題,你只需要使用record函數的內置參數,它會返回整個對象。

def render_Status(self, value, record, column):
    if value == 'Выполнено':
        column.attrs = {'td': {'class': 'table-success text-center align-middle'}}

    elif value == 'В работе':
        column.attrs = {'td': {'class': 'table-warning text-center align-middle'}}

    elif record.Term_Implementation <= date.today():
        column.attrs = {'td': {'class': 'table-danger text-center align-middle'}}

    else:
        column.attrs = {'td': {'class': 'text-center align-middle'}}

    return value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM