对于较新版本的Django,请在下面查看Sjoerd答案
这是完成你想要做的事情的最佳方法:
from django.db.models import get_app, get_modelsapp = 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 # ...



