Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1053597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:16:39+00:00 2026-05-16T17:16:39+00:00

Given a Django model, I’m trying to list all of its fields. I’ve seen

  • 0

Given a Django model, I’m trying to list all of its fields. I’ve seen some examples of doing this using the _meta model attribute, but doesn’t the underscore in front of meta indicate that the _meta attribute is a private attribute and shouldn’t be accessed directly? … Because, for example, the layout of _meta could change in the future and not be a stable API?

Is _meta an exception to this rule? Is it stable and ready to use or is it considered bad practice to access it? Or is there a function or some other way to introspect the fields of a model without using the _meta attribute? Below is a list of some links showing how to do this using the _meta attribute

Any advice is much appreciated.

django object get/set field

http://www.djangofoo.com/80/get-list-model-fields

How to introspect django model fields?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:16:40+00:00Added an answer on May 16, 2026 at 5:16 pm

    _meta is private, but it’s relatively stable. There are efforts to formalise it, document it and remove the underscore, which might happen before 1.3 or 1.4. I imagine effort will be made to ensure things are backwards compatible, because lots of people have been using it anyway.

    If you’re particularly concerned about compatibility, write a function that takes a model and returns the fields. This means if something does change in the future, you only have to change one function.

    def get_model_fields(model):
        return model._meta.fields
    

    I believe this will return a list of Field objects. To get the value of each field from the instance, use getattr(instance, field.name).

    Update: Django contributors are working on an API to replace the _Meta object as part of a Google Summer of Code. See:
    – https://groups.google.com/forum/#!topic/django-developers/hD4roZq0wyk
    – https://code.djangoproject.com/wiki/new_meta_api

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have a given django model class like this: class BaseClass(models.Model): some_field =
I'm using Python/Django, but this is more about the data model and how I
Given: from django.db import models class Food(models.Model): Food, by name. name = models.CharField(max_length=25) class
Given a class: from django.db import models class Person(models.Model): name = models.CharField(max_length=20) Is it
Given a Django model likeso: from django.db import models class MyModel(models.Model): textfield = models.TextField()
I'm trying to create a Django model that handles the following: An Item can
I have a Django project, that has a Address model. This is used in
In Django, given excerpts from an application animals likeso: A animals/models.py with: from django.db
I'm struggling with the design of a django application. Given the following models: class
Given a situation in Django 1.0 where you have extra data on a Many-to-Many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.