【Django】获取 models类的属性字段

获取数据表的字段

from core import models
temp_val = models.FactorInfo._meta.get_fields()
field_list = [i.name for i in temp_val]
# ['enterpriseinfo', 'siteinfo', 'enterprisefactoremissions', 'mufflerfactoremissions', 'datacollectfactor', 'id', 'type', 'name', 'column', 'minValue', 'maxValue', 'unit', 'status', 'created_at', 'updated_at']

# 不包括多对多以及其他外表外部关联字段.
for field in models.FactorInfo._meta.fields:
    print(field.name)
    print(field.verbose_name)
# ['id', 'type', 'name', 'column', 'minValue', 'maxValue', 'unit', 'status', 'created_at', 'updated_at']

posted @ 2023-05-15 17:08  是阿杰呀  阅读(153)  评论(0)    收藏  举报