1
def export_as_xls(modeladmin, request, queryset):
"""
Generic xls export admin action.
"""
if not request.user.is_staff:
raise PermissionDenied
opts = modeladmin.model._meta
wb = Workbook()
ws0 = wb.add_sheet('0')
col = 0
field_names = []
# write header row
for field in opts.fields:
ws0.write(0, col, field._meta.verbose_name)
field_names.append(field._meta.verbose_name)
col = col + 1
如果我嘗試出口XLS我有這樣的錯誤:下拉列表AutoField對象有沒有屬性「_meta - field._meta.verbose_name
'AutoField' object has no attribute '_meta'
有了:field.name
這個工作,但我需要冗長的名字