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!

txf
  • 19
  • 3

1 Answers1

0

you can relate the sub-models by adding attribute (page) like this:

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

in each of subclasses (DicSoftware and Simulation) and then in the content_panels of main clustarable model, use the related_name attributes of each sub-class: FieldPanel("<sub-class>_model", classname="col10"),

  • Thanks for your answer. I try to do as you said, but this can not solve my problem. The workflow are as follows. First, I add some software information in table DicSoftware. Then, I add one simulation tupple in table Simulation. When I add a simulation tupple, I should specify the software names, the software input file and so on. – txf Jul 12 '21 at 08:41