Django:我如何找到ORM知道的模型列表? [英] Django : How can I find a list of models that the ORM knows?
本文介绍了Django:我如何找到ORM知道的模型列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
在Django中,有没有一个地方可以找到ORM知道的模型列表? p>简单解决方案:
import django.apps
django.apps.apps.get_models()
在Django 1.7之前,请改用:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
include_auto_created
参数确保通过ManyToManyField
s隐式创建的表也将被检索。 p>In Django, is there a place I can get a list of or look up the models that the ORM knows about?
解决方案Simple solution:
import django.apps django.apps.apps.get_models()
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 byManyToManyField
s will be retrieved as well.这篇关于Django:我如何找到ORM知道的模型列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文