2015-11-19 194 views
0

我目前正在研究'Job/command抽象管理器'。 我想要完成的是: - jobInvoker定義參數,例如要調用的類,要設置的參數以便初始化(key/val) - 工具可能需要使用特定的作業調用程序,並且需要定義(例如:需要設置實際的命令行來啓動'ShellJobinvoker')Python Django自動填充內聯表格

我需要在AtgcTool管理員(我已經使用嵌套嵌入式https://github.com/Soaa-/django-nested-inlines)中添加以下操作: 在JobInvoker選擇,自動添加的字段從JobInvokerExpectedParam定義的設置預期PARAMS

作業調用定義:

class JobInvoker(models.Model): 
    name = models.CharField("ServiceJob invoker name", max_length=50, null=False) 
    description = models.TextField("ServiceJob invoker description", null=True, blank=True) 
    isAvailable = models.BooleanField("ServiceJob availability flag", default=True) 
    backUpAverage = models.IntegerField("ServiceJob load average value before switching to backUp", default=0) 
    backUp = models.ForeignKey('self', null=True, blank=True, related_name='backUpService') 
    clazz = models.CharField("ServiceJob invoker injected class name", max_length=150, null=False, 
          choices=settings.ATGC_SERVICES['SERVICE_JOB_INVOKER_IMPL']) 

    def __str__(self): 
     return self.name 


class JobInvokerExpectedParam(Ordered): 
    class Meta: 
     db_table = 'atgc_job_invoker_param' 
    name = models.CharField("Key", max_length=100, blank=True, null=False) 
    default = models.CharField("Default", max_length=255, null=True, blank=True) 
    job_invoker = models.ForeignKey(JobInvoker) 

工具模型:

class AtgcTool(models.Model): 
    name = models.CharField("Service Tool name", max_length=50) 
    version = models.CharField("Service tool current version", max_length=15) 
    released = models.DateField("Service tool release date", null=True) 
    online = models.DateField("Service tool online last update date", null=True) 
    description = models.TextField("Service Tool description text", null=True, blank=True) 
    slug = models.TextField("Service tool description slug", null=True, blank=True) 

對於「運行PARAMS」

class RunnableOn(models.Model): 
    """ 
    Specify if a is ServiceTool 'runnable on' a ServiceJobInvoker 
    """ 
    class Meta: 
     db_table = 'atgc_tool_runnable_on' 
    invoker = models.OneToOneField(JobInvoker) 
    tool = models.OneToOneField(AtgcTool) 
    threshold = models.IntegerField("Load average threshold", default=100) 


class RunnableOnParam(KeyValPair): 
    class Meta: 
     db_table = 'atgc_tool_run_param' 
    mandatoryValue = True 
    runOn = models.ForeignKey(RunnableOn) 

回答

0

我終於找到了一個解決方案,使用簡單地與相關模型類多對多關係定義參數我通緝。爲了過濾內聯數據,我簡單地過濾了相關的表格數據。