UPDATE
для более новых версий чека Django Sjoerd ответ ниже
Оригинальный ответ с 2012 года:
Это лучший способ выполнить то, что вы хотите сделать:
from django.db.models import get_app, get_models
app = get_app('my_application_name')
for model in get_models(app):
# do something with the model
В этом примере model
- это фактическая модель, поэтому вы можете сделать с ней множество вещей:
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
# ...