Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
简易的导出功能。
使用了
django.core.serializers
模块里提供的转化为字符串功能,并将序列化得到的JSON转化为Excel文件,返回给用户。Excel文件中每列的名称来自模型定义中每个field的verbose_name
.Django的序列化默认使用主键作为外键的输出。为了提高可读性,利用了Django的natural key功能,让序列化时可以指定外键的表现形式。例如,通过设置奖池
Pool
模型的natural key为奖池名称,在导出奖池记录PoolRecord
时,其中含有的Pool
foreign key列将包括奖池名称字符串,而不是对应Pool
对象的id。本PR中包含了一些类的natural key定义,后续可以根据实际使用情况进行维护。导出功能在设计时只考虑了“导出”,没有考虑从获得的Excel文件恢复数据库对象,所以natural key并不一定能唯一确定对象,没有完全实现Django的要求,这点需要注意。