0Pricing
Django Academy · Lesson

Importing and Inspecting Models

Pull in models and look at their fields.

Importing and Inspecting Models is a free Django Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Bring Your Models In

Before you can query data, you import the model class into the shell. Pull it from the app where you defined it.

>>> from blog.models import Post

The App Path Pattern

The import path is always appname.models. So a Post in the blog app lives at blog.models, matching your folder layout.

Confirm It Imported

Type the class name alone to see Django confirm the model. It echoes the class so you know the import worked.

>>> Post
<class 'blog.models.Post'>

Every Model Has a Manager

Each model carries a manager called objects. It is your gateway to every query, like fetching or counting rows.

>>> Post.objects

Peek at the Fields

To list a model's columns, read its hidden _meta object. It exposes the fields Django mapped to your table.

>>> Post._meta.get_fields()

Field Names at a Glance

A quick comprehension turns that into a clean list of field names, handy when you forget a column.

>>> [f.name for f in Post._meta.get_fields()]

Inspect One Field

You can grab a single field by name with get_field. It returns the field object so you can read its details.

>>> Post._meta.get_field('title')

Read a Field's Type

Ask a field for its type with type(). This tells you whether a column is a CharField, IntegerField, and so on.

>>> type(Post._meta.get_field('title'))

Use Python's help

Plain Python tools still work. Run help on the model to read its docstring and see available attributes.

>>> help(Post)

Import More Than One

Need several models? Import them together on one line so you can cross-reference data without retyping.

>>> from blog.models import Post, Comment

Inspect Before You Query

Inspecting first saves time. Knowing the exact field names prevents typos when you start filtering real records.

Quick Check

How do you list the fields a model defines?

Recap

You imported models with appname.models, met the objects manager, and used _meta to inspect fields before querying. 🔍

Frequently asked questions

Is the “Importing and Inspecting Models” lesson free?

Yes — the full text of “Importing and Inspecting Models” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “Importing and Inspecting Models”?

Pull in models and look at their fields. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Importing and Inspecting Models” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Launching python manage.py shell
  2. Importing and Inspecting Models
  3. Creating and Saving Objects Live
  4. shell_plus and Better Tooling
← Back to Django Academy