Python 当模型具有相同的字段但不同的帮助文本时,django中是否可以进行继承

Python 当模型具有相同的字段但不同的帮助文本时,django中是否可以进行继承,python,django,django-models,Python,Django,Django Models,我有两个模型有完全相同的字段。唯一的区别是,每个项目的帮助文本不同。是有没有一种方法可以消除这种重复,例如使用继承或其他方法? 这是我的两门课 class IgnoreListGsheet(models.Model): key = models.CharField(max_length=255, help_text="The key of the Google Sheet holding the ignore list.") worksheet_name =

我有两个模型有完全相同的字段。唯一的区别是,每个项目的帮助文本不同。是有没有一种方法可以消除这种重复,例如使用继承或其他方法? 这是我的两门课

class IgnoreListGsheet(models.Model):
    key = models.CharField(max_length=255, help_text="The key of the Google Sheet holding the ignore list.")
    worksheet_name = models.CharField(max_length=255, help_text="The name of the workspace containing the ignore list")
    column_name = models.CharField(max_length=255, help_text="The column name containing the ignore list.")

    def __str__(self):
        return self.key


class RespondListGsheet(models.Model):
    key = models.CharField(max_length=255, help_text="The key of the Google Sheet holding the respond to list.")
    worksheet_name = models.CharField(max_length=255, help_text="The name of the workspace containing the respond to accounts")
    column_name = models.CharField(max_length=255, help_text="The column name containing the respond to accounts.")

    def __str__(self):
        return self.key
希望这将有助于:

类基本表(models.Model):
key=models.CharField(最大长度=255,帮助文本=)
工作表名称=models.CharField(最大长度=255,帮助文本=)
列名称=models.CharField(最大长度=255,帮助文本=)
定义(自我):
返回自密钥
类IgnoreListGsheet(基表):
类元:
help_text={'key':'foo','sheet_name':'bar','column_name':'baz',}

即使这是表单的解决方案,它也可能转化为模型。如果没有,则您可能必须将其添加到表单中,并呈现它们,而不是模型本身。

您可以只使用一个模式,并使用布尔响应字段来标记应使用的帮助文本,然后,使用两个函数返回属性的帮助文本值。属性不直接翻译,但第二个建议有效。非常感谢。