列出表中的字段

Hul*_*ulk 11 python django

有没有办法列出django模型中表格中的字段

 class Profile(models.Model):
    user = models.ForeignKey(User, unique=True)
    name = models.ForeignKey(School)
    emp = models.ForeignKey(User, unique=True)
Run Code Online (Sandbox Code Playgroud)

如何列出表Profile中的字段名称,(就像desc Profile;在mysql中)

谢谢.

Ign*_*ams 14

Profile._meta.fields会给你一个字段列表.name字段对象的属性包含字段的名称.Profile._meta.get_fields_with_model()将返回的2元组的列表(field, model),以model作为None如果该字段中Profile.