使用 XLRD 导入 Django 递归树
我的数据(电子表格):
'1',,,
,'1.1',,
,,'1.1.1',
,,'1.1.2',
,,'1.1.3',
,'1.2',,
,'1.3',,
,,'1.3.1',
,,'1.3.2',
,,'1.3.3',
'2',,,
,'2.1',,
,,'2.1.1',
,,,'2.1.1.1'
,,,'2.1.1.2'
,,,'2.1.1.3'
我的模型:
class Vocabulary(models.Model):
name = CharField(max_length=60)
class Concept(models.Model):
parent = ForeignKey('self', blank=True, null=True)
vocabulary = ForeignKey(Vocabulary)
name = CharField(max_length=60)
order = IntegerField(default=0)
我想要做什么:
def recurse(sheet):
'Recurse outer edges of the tree saving concepts.'
+ 'Imply subtree order numbers. There are no numbers in the real data.'
My data (spreadsheet):
'1',,,
,'1.1',,
,,'1.1.1',
,,'1.1.2',
,,'1.1.3',
,'1.2',,
,'1.3',,
,,'1.3.1',
,,'1.3.2',
,,'1.3.3',
'2',,,
,'2.1',,
,,'2.1.1',
,,,'2.1.1.1'
,,,'2.1.1.2'
,,,'2.1.1.3'
My model:
class Vocabulary(models.Model):
name = CharField(max_length=60)
class Concept(models.Model):
parent = ForeignKey('self', blank=True, null=True)
vocabulary = ForeignKey(Vocabulary)
name = CharField(max_length=60)
order = IntegerField(default=0)
What I am trying to do:
def recurse(sheet):
'Recurse outer edges of the tree saving concepts.'
+ 'Imply subtree order numbers. There are no numbers in the real data.'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不容易弄清楚,只是分享一下。这就是我使用 Python XLRD 和 Django 将层次结构从 Excel 导入到简单邻接列表树存储的方法。
关键字:层次结构、从 Excel 导入树、导入逗号/制表符分隔的层次结构、从 Excel 导入类别、Python Django XLRD 树导入
It wasn't easy to figure out, just to share it. This is how I imported hierarchy from Excel to simple adjacency list tree store using Python XLRD and Django.
Keywords: hierarchy, import tree from Excel, import comma/tab delimited hierarchy, import categories from Excel, Python Django XLRD tree import