Django : How can I find a list of models that the ORM knows?

Simple solution:

import django.apps
django.apps.apps.get_models()

By default apps.get_models() don’t include

  • auto-created models for many-to-many relations without
    an explicit intermediate table
  • models that have been swapped out.

If you want to include these as well,

django.apps.apps.get_models(include_auto_created=True, include_swapped=True)

Prior to Django 1.7, instead use:

from django.db import models
models.get_models(include_auto_created=True)

The include_auto_created parameter ensures that through tables implicitly created by ManyToManyFields will be retrieved as well.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)