Categories
Python Answers

How to get list of model fields with Python Django?

Spread the love

To get list of model fields with Python Django, we use MyModel._meta.get_fields().

For instance, we write

[f.name for f in MyModel._meta.get_fields()]

to get all the fields with MyModel._meta.get_fields().

Then we get the name of each field with f.name.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *