Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created September 18, 2013 19:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kissgyorgy/6614702 to your computer and use it in GitHub Desktop.
Save kissgyorgy/6614702 to your computer and use it in GitHub Desktop.
Django: Get list of models from app
# http://stackoverflow.com/questions/8702772/django-get-list-of-models-in-application
from django.db.models import get_app, get_models
app = get_app('my_application_name')
for model in get_models(app):
new_object = model() # Create an instance of that model
model.objects.filter(...) # Query the objects of that model
model._meta.db_table # Get the name of the model in the database
model._meta.verbose_name # Get a verbose name of the model
# ...
@fmalina
Copy link

fmalina commented Apr 19, 2017

Not working in latest Django.

@udartsev
Copy link

Yep. Doesn`t work with Django 2+ versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment