在我的问题中,有三种相关的模式:
class DicSoftware(index.Indexed, ClusterableModel):
name = models.CharField("软件名称", max_length=255, blank=True)
version = models.CharField("版本号", max_length=255, blank=True)
panels = [MultiFieldPanel([
FieldPanel('name', classname="col10"),
FieldPanel('version', classname="col10"),
], "模拟软件")]
class Simulation(index.Indexed, ClusterableModel):
name = models.CharField("算例名称", max_length=255, blank=True)
software = ParentalManyToManyField('DicSoftware', related_name='模拟软件')
panels = [ MultiFieldPanel([
FieldPanel('name', classname="col10"),
FieldPanel('software', classname="col10"),
], "算例")]
使用上述两个模型,wagtail将自动生成表simulation_software,其中包含三个字段: id、simulation_id、dicsoftware_id。但是,我想在表simulation_software、inputFile和inputFilePath中添加其他两个字段。最后一个表simulation_software的模型应该是:
class SimulationSoftware(index.Indexed, ClusterableModel):
simulation = models.ForeignKey(Simulation, verbose_name="算例", help_text="/admin/home/simulation/", on_delete=models.CASCADE, blank=True, null=True, related_name='+')
software = models.ForeignKey(DicSoftware, verbose_name="模拟软件", help_text="/admin/home/dicsoftware/", on_delete=models.CASCADE, blank=True, null=True, related_name='+')
#把读入的文件内容存入inputJSON
inputFile = models.FileField("初始化参数文件", upload_to="files", default="")
outputFilePath = models.CharField("结果文件存储位置", max_length=255, blank=True)
panels = [MultiFieldPanel([
FieldPanel('simulation', classname="col10"),
FieldPanel('software', classname="col10"),
FieldPanel('inputFile', classname="col10"),
FieldPanel('outputFilePath', classname="col10"),
], "算例输入")]
当用户添加一个模拟时,他们必须提供如下信息:
在一个仿真中,可以有一个或多个软件。如果在这个模拟中使用了两个软件,用户应该同时提供这些信息,__:
第一款软件的inputFile和outputFilePath.
如何管理软件(一个或多个软件)的inputFiles和outputFilePaths的模型结构和输入面板。
有人能给我一些建议吗?希望你能帮忙。非常感谢!
发布于 2021-07-12 07:44:10
您可以通过添加属性(页面)来关联子模型,如下所示:
page = ParentalKey('SimulationSoftware', related_name='<sub-class>_model', on_delete=models.CASCADE)
在每个子类(DicSoftware和仿真)中,然后在主可聚集模型的content_panels中,使用每个子类的related_name属性:FieldPanel("<sub-class>_model", classname="col10"),
。
https://stackoverflow.com/questions/68250050
复制相似问题