Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List fields present in a table

Tags:

python

django

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.

like image 687
Hulk Avatar asked Mar 03 '10 05:03

Hulk


People also ask

What are the fields in a table?

A table has records (rows) and fields (columns). Fields have different types of data, such as text, numbers, dates, and hyperlinks.

How do I get all the field names of a table?

Hi, You can go to System Definition -> Dictionary. Here you can type the table name and find all the related field names.


1 Answers

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.

like image 72
Ignacio Vazquez-Abrams Avatar answered Oct 18 '22 02:10

Ignacio Vazquez-Abrams