On Fri, Jun 20, 2008 at 7:06 AM, Beetle B. <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I needed a way to get a list of all models in a Django project.
>
> I was told in IRC that I can use get_models from django.db.models.
>
> I'm not sure this is documented in the docs. Is it "safe" to use (as
> in this method and its behavior is not expected to change in the
> future)?

I'm pretty sure those functions are not documented, which is
unfortunate, because they are quite useful. They are quite safe, quite
supported, and unlikely to be changed or deprecated any time soon.

Short version:

>>> from django.db.models import get_model, get_models, get_apps

>>> get_apps()
[... list of application modules ]

>>> a = get_app('my_app')
>>> print a
<module 'testproject.myapp' from .../testproject/myapp.models.pyc>

>>> get_models(a)
[... list of model classes ...]

>>> get_model('myapp','Author')
<class 'myapp.models.Author'>

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to