-
-
Save om2c0de/a5053bd9abe147474ebed334224752ab to your computer and use it in GitHub Desktop.
Django: Get list of models from app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment