Open
Conversation
接下来需要为现有的模型增加自然键的定义,并且尝试增加”选择导出的列“的功能。 有可能需要把导出逻辑放到另一个页面上。
考虑到我们定义natural key只要是为了让导出的excel中外键处理更美观,没有全部加natural_key。 后面如果遇到有导出的是id的情况,可以再补充。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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时,其中含有的Poolforeign key列将包括奖池名称字符串,而不是对应Pool对象的id。本PR中包含了一些类的natural key定义,后续可以根据实际使用情况进行维护。导出功能在设计时只考虑了“导出”,没有考虑从获得的Excel文件恢复数据库对象,所以natural key并不一定能唯一确定对象,没有完全实现Django的要求,这点需要注意。