django导入导出数据
使用django import export
from import_export.admin import ImportExportModelAdmin
from import_export import resources
class SendListResource(resources.ModelResource):
#使用field对字段进行加工
name = Field(attribute= 'name',column_name= '姓名')
id_number = Field(attribute= 'id_number',column_name='身份证号')
phone = Field(attribute='phone',column_name='手机号')
Place_of_residence = Field(attribute='Place_of_residence',column_name='旅居地')
C_residence = Field(attribute='C_residence',column_name='现居住地')
#外键的导入导出
doc_no = Field(attribute='doc_no',column_name='文件函号',widget=ForeignKeyWidget(Doc_Letter_No,'doc_no'))
remark = Field(attribute='remark',column_name='备注')
send_time = Field(attribute='send_time',column_name='派送日期')
send_unit = Field(attribute='send_unit',column_name='派送单位',widget=ForeignKeyWidget(Township,'name'))
class Meta:
model = SendList
exclude = ('created_time','modified_time')
class SendListAdmin(ImportExportModelAdmin):
# fields = (('name','id_number','phone'),'content')
list_display =('name','id_number','phone','Place_of_residence','C_residence','remark','doc_no','send_time','send_unit')
search_fields = ['name','phone','id_number','Place_of_residence']
list_filter = ['send_time','send_unit','doc_no','remark']
date_hierarchy = 'send_time'
list_per_page = 20
resource_class = SendListResource
admin.site.register(SendList,SendListAdmin)
博观而约取,厚积而薄发。