Django 如何列出未从基类继承的列?

Django 如何列出未从基类继承的列?,django,inheritance,django-models,Django,Inheritance,Django Models,我有这门课: class DataCommonInfoText(models.Model): a_col = model.TextField() def is_data(self): return True class Meta: abstract = True 以及从中继承的类: class MoreData(DataCommonInfoText): another_col = models.IntegerField() 我

我有这门课:

class DataCommonInfoText(models.Model):
    a_col = model.TextField()
    def is_data(self):
        return True

    class Meta:
        abstract = True
以及从中继承的类:

class MoreData(DataCommonInfoText):
    another_col = models.IntegerField()

我想将
MoreData
中未从
DataCommonInfoText
继承的所有列列作为字符串列出。如何执行此操作?

从抽象类继承时,该字段被视为本地()。 因此,为了只获得当前类中实际声明的字段,您必须计算当前类和基类中的所有字段,然后在这两者之间执行集减法

要获取某个模型的所有字段,请使用:
model.\u meta.get\u fields()

例:

这应该可以解决问题

最后一步,如果要将项目放在字符串上,可以使用
join
和所需的任何分隔符:

fieldStr = ", ".join(derivedOnlyFields)
fieldStr = ", ".join(derivedOnlyFields)