如何使用 django mptt?
我有一个模型:
class Company(models.Model):
name = models.CharField( max_length=100)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Company, order_insertion_by=['name'])
那么
class Financials(models.Model):
year = models.IntegerField()
revenue = models.DecimalField(max_digits = 10, decimal_places = 2)
如何将 Financials
作为子项添加到 mptt 树结构中的 Company
中?
I have a model:
class Company(models.Model):
name = models.CharField( max_length=100)
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
mptt.register(Company, order_insertion_by=['name'])
and
class Financials(models.Model):
year = models.IntegerField()
revenue = models.DecimalField(max_digits = 10, decimal_places = 2)
So how can I add Financials
as a child to Company
in the mptt tree structure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白你的问题。 一棵树存储一种类型的对象,在您的例子中是 Company。 要将财务链接到公司,只需添加从财务到公司的外键。
如果这没有帮助,请扩展您的问题,向我们提供有关您想要实现的目标的更多详细信息。
I don't quite follow your question. A tree stores one type of object, in your case Company. To link Financials to Company just add a foreign key from Financials to Company.
If this doesn't help please expand your question to give us some more detail about what you are trying to achieve.