我正在尝试将文档的各个部分存储在 Django 应用程序中。模型看起来像:
class Section(models.Model):
project = models.ForeignKey(Project)
parent_section = models.ForeignKey('Section', blank=True, null=True, related_name='child_set')
predecessor_section = models.ForeignKey('Section', blank=True, null=True, related_name='predecessor_set')
name = models.CharField(max_length=100)
text = models.TextField(blank=True, null=True)
我创建了很多部分,将它们链接起来(parent_section、previous_section)并通过调用它们的每个保存方法来存储它们。但是,当我在保存后查看表时,没有设置 parent_section_id 和前任部分_id,即使我在保存之前附加了对象。
我认为这与一些 parent_section 实例没有分配 id 的事实有关,因为它们的实例尚未存储,但使用手动事务无法解决问题。
对此有什么想法吗?
干杯,马克斯