def save_file(self, filename, encoding='utf8', headers=None,
                  convertors=None, display=True, **kwargs):
        """
        save result to a csv file.
        display = True will convert value according choices value
        """
        global save_file
        
        convertors = convertors or {}
        headers = headers or []
        
        fields = self.get_fields()
        _header = []
        for i, column in enumerate(fields):
            if column.name not in convertors:
                if display:
                    def f(value, data):
                        return column.get_display_value(value)

                    convertors[column.name] = f
            flag = False
            for j in headers:
                if not isinstance(j, dict):
                    raise ValueError("Header should be a list of dict, but {} type found".format(type(j)))
                if j['name'] == column.name:
                    _header.append(j)
                    flag = True
                    break
            if not flag:
                d = {'name':column.name}
                if display:
                    d['title'] = column.verbose_name or column.name
                else:
                    d['title'] = column.name
                _header.append(d)

        return save_file(self.run(), filename, encoding=encoding,
                         headers=_header, convertors=convertors, **kwargs)
def save_file ( self , filename , encoding = 'utf8' , headers = None , convertors = None , display = True , ** kwargs ) : global save_file convertors = convertors or { } headers = headers or [ ] fields = self . get_fields ( ) _header = [ ] for i , column in enumerate ( fields ) : if column . name not in convertors : if display : def f ( value , data ) : return column . get_display_value ( value ) convertors [ column . name ] = f flag = False for j in headers : if not isinstance ( j , dict ) : raise ValueError ( "Header should be a list of dict, but {} type found" . format ( type ( j ) ) ) if j [ 'name' ] == column . name : _header . append ( j ) flag = True break if not flag : d = { 'name' : column . name } if display : d [ 'title' ] = column . verbose_name or column . name else : d [ 'title' ] = column . name _header . append ( d ) return save_file ( self . run ( ) , filename , encoding = encoding , headers = _header , convertors = convertors , ** kwargs )
save result to a csv file.
        display = True will convert value according choices value