0

In my question, there are three related models:

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"),
     ], "算例")]

With these two models above, wagtail automatically generate table simulation_software with three fields, id, simulation_id, dicsoftware_id. However, I want to add other two fields in table simulation_software, inputFile and inputFilePath. The model of the final table simulation_software should be:

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"),
    ], "算例输入")]

When users add one simulation, they have to give the information as follows:

  1. simulation name.
  2. specify the software(one or more software) used in this simulation.

In one simulation, there can be one or more sofware. If two software are used in this simulation, users should give these information at the same time:

  1. the first sofware's inputFile and outputFilePath.
  2. the second sofware's inputFile and outputFilePath.

How to manage the models' structure and the input panels for inputFiles and outputFilePaths of the software(one or more software).

Anyone can give me some sugguestions? Wish for your help. Thank you very much!

4

1 回答 1

0

您可以通过添加属性(页面)来关联子模型,如下所示:

page = ParentalKey('SimulationSoftware', related_name='<sub-class>_model', on_delete=models.CASCADE)

在每个子类(DicSoftware 和 Simulation)中,然后在 main clustarable 模型的 content_panels 中,使用每个子类的related_name 属性:FieldPanel("<sub-class>_model", classname="col10"),

于 2021-07-12T07:44:10.650 回答