(self, field_name, row)
return item
返回某一列的头信息, 一个 :class:`ResultHeader` 实例.

        :param field_name: 列的名字
        :param row: :class:`ResultHeader` 实例
返回某一列的头信息, 一个 :class:`ResultHeader` 实例.
返回某一列的头信息 一个 : class : ResultHeader 实例 .
def result_header(self, field_name, row):
        """
        返回某一列的头信息, 一个 :class:`ResultHeader` 实例.

        :param field_name: 列的名字
        :param row: :class:`ResultHeader` 实例
        """
        ordering_field_columns = self.ordering_field_columns
        item = ResultHeader(field_name, row)
        text, attr = label_for_field(field_name, self.model,
                                     model_admin=self,
                                     return_attr=True
                                     )
        item.text = text
        item.attr = attr
        if attr and not getattr(attr, "admin_order_field", None):
            return item

        # 接下来就是处理列排序的问题了
        th_classes = ['sortable']
        order_type = ''
        new_order_type = 'desc'
        sort_priority = 0
        sorted = False
        # 判断当前列是否已经排序
        if field_name in ordering_field_columns:
            sorted = True
            order_type = ordering_field_columns.get(field_name).lower()
            sort_priority = list(ordering_field_columns.keys()).index(field_name) + 1
            th_classes.append('sorted %sending' % order_type)
            new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type]

        # build new ordering param
        o_list_asc = []  # URL for making this field the primary sort
        o_list_desc = []  # URL for making this field the primary sort
        o_list_remove = []  # URL for removing this field from sort
        o_list_toggle = []  # URL for toggling order type for this field
        make_qs_param = lambda t, n: ('-' if t == 'desc' else '') + str(n)

        for j, ot in ordering_field_columns.items():
            if j == field_name:  # Same column
                param = make_qs_param(new_order_type, j)
                # We want clicking on this header to bring the ordering to the
                # front
                o_list_asc.insert(0, j)
                o_list_desc.insert(0, '-' + j)
                o_list_toggle.append(param)
                # o_list_remove - omit
            else:
                param = make_qs_param(ot, j)
                o_list_asc.append(param)
                o_list_desc.append(param)
                o_list_toggle.append(param)
                o_list_remove.append(param)

        if field_name not in ordering_field_columns:
            o_list_asc.insert(0, field_name)
            o_list_desc.insert(0, '-' + field_name)

        item.sorted = sorted
        item.sortable = True
        item.ascending = (order_type == "asc")
        item.sort_priority = sort_priority

        # 列排序菜单的内容
        menus = [
            ('asc', o_list_asc, 'caret-up', _(u'Sort ASC')),
            ('desc', o_list_desc, 'caret-down', _(u'Sort DESC')),
        ]
        if sorted:
            row['num_sorted_fields'] = row['num_sorted_fields'] + 1
            menus.append((None, o_list_remove, 'times', _(u'Cancel Sort')))
            item.btns.append('<a class="toggle" href="%s"><i class="fa fa-%s"></i></a>' % (
                self.get_query_string({ORDER_VAR: '.'.join(o_list_toggle)}), 'sort-up' if order_type == "asc" else 'sort-down'))

        item.menus.extend(['<li%s><a href="%s" class="active"><i class="fa fa-%s"></i> %s</a></li>' %
                         (
                             (' class="active"' if sorted and order_type == i[
                              0] else ''),
                           self.get_query_string({ORDER_VAR: '.'.join(i[1])}), i[2], i[3]) for i in menus])
        item.classes.extend(th_classes)

        return item
def result_header ( self , field_name , row ) : ordering_field_columns = self . ordering_field_columns item = ResultHeader ( field_name , row ) text , attr = label_for_field ( field_name , self . model , model_admin = self , return_attr = True ) item . text = text item . attr = attr if attr and not getattr ( attr , "admin_order_field" , None ) : return item # 接下来就是处理列排序的问题了 th_classes = [ 'sortable' ] order_type = '' new_order_type = 'desc' sort_priority = 0 sorted = False # 判断当前列是否已经排序 if field_name in ordering_field_columns : sorted = True order_type = ordering_field_columns . get ( field_name ) . lower ( ) sort_priority = list ( ordering_field_columns . keys ( ) ) . index ( field_name ) + 1 th_classes . append ( 'sorted %sending' % order_type ) new_order_type = { 'asc' : 'desc' , 'desc' : 'asc' } [ order_type ] # build new ordering param o_list_asc = [ ] # URL for making this field the primary sort o_list_desc = [ ] # URL for making this field the primary sort o_list_remove = [ ] # URL for removing this field from sort o_list_toggle = [ ] # URL for toggling order type for this field make_qs_param = lambda t , n : ( '-' if t == 'desc' else '' ) + str ( n ) for j , ot in ordering_field_columns . items ( ) : if j == field_name : # Same column param = make_qs_param ( new_order_type , j ) # We want clicking on this header to bring the ordering to the # front o_list_asc . insert ( 0 , j ) o_list_desc . insert ( 0 , '-' + j ) o_list_toggle . append ( param ) # o_list_remove - omit else : param = make_qs_param ( ot , j ) o_list_asc . append ( param ) o_list_desc . append ( param ) o_list_toggle . append ( param ) o_list_remove . append ( param ) if field_name not in ordering_field_columns : o_list_asc . insert ( 0 , field_name ) o_list_desc . insert ( 0 , '-' + field_name ) item . sorted = sorted item . sortable = True item . ascending = ( order_type == "asc" ) item . sort_priority = sort_priority # 列排序菜单的内容 menus = [ ( 'asc' , o_list_asc , 'caret-up' , _ ( u'Sort ASC' ) ) , ( 'desc' , o_list_desc , 'caret-down' , _ ( u'Sort DESC' ) ) , ] if sorted : row [ 'num_sorted_fields' ] = row [ 'num_sorted_fields' ] + 1 menus . append ( ( None , o_list_remove , 'times' , _ ( u'Cancel Sort' ) ) ) item . btns . append ( '<a class="toggle" href="%s"><i class="fa fa-%s"></i></a>' % ( self . get_query_string ( { ORDER_VAR : '.' . join ( o_list_toggle ) } ) , 'sort-up' if order_type == "asc" else 'sort-down' ) ) item . menus . extend ( [ '<li%s><a href="%s" class="active"><i class="fa fa-%s"></i> %s</a></li>' % ( ( ' class="active"' if sorted and order_type == i [ 0 ] else '' ) , self . get_query_string ( { ORDER_VAR : '.' . join ( i [ 1 ] ) } ) , i [ 2 ] , i [ 3 ] ) for i in menus ] ) item . classes . extend ( th_classes ) return item