列出表中存在的字段 [英] List fields present in a table
本文介绍了列出表中存在的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类配置文件(models.Model)中有没有办法列出表中存在的字段)
user = models.ForeignKey(User,unique = True)
name = models.ForeignKey(School)
emp = models.ForeignKey(User,unique = True)
如何从表格中列出归档名称(就像desc配置文件;在mysql中)
谢谢。
解决方案
Profile._meta.fields
会给你一个字段列表。字段对象的名称
属性包含字段的名称。 Profile._meta.get_fields_with_model()
将返回一个2元组的列表,其中(field,model)
code> model 正在无
如果该字段位于配置文件
p>
Is there any way to to list out the fields present in a table in django models
class Profile(models.Model):
user = models.ForeignKey(User, unique=True)
name = models.ForeignKey(School)
emp = models.ForeignKey(User, unique=True)
How to list out the filed names from the table Profile,(just like desc Profile; in mysql )
thanks.
解决方案
Profile._meta.fields
will get you a list of fields. The name
property of the field object contains the name of the field. Profile._meta.get_fields_with_model()
will return a list of 2-tuples of (field, model)
, with model
being None
if the field is in Profile
.
这篇关于列出表中存在的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文