Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a list of all installed applications in Django and their attributes

In my Django website, I'm creating a class that interact dynamically with other applications installed in the website. I have to do a manipulation on each field of each application.

So I want to save the name of all installed applications in a list and get the attributes of each one. There is a way to do that using an iterator or something else ?

like image 410
bnabilos Avatar asked Nov 06 '10 00:11

bnabilos


People also ask

How do I see installed apps in Django?

The list of installed applications is defined in settings. INSTALLED_APPS . It contains a tuple of strings, so you can iterate on it to access each application's name.

What file contains the list of installed apps in a Django project?

In your settings.py file, you will find INSTALLED_APPS. Apps listed in INSTALLED_APPS are provided by Django for the developer's comfort.

What is app config in Django?

AppConfig subclasses may be defined anywhere. The apps.py convention merely allows Django to load them automatically when INSTALLED_APPS contains the path to an application module rather than the path to a configuration class.


1 Answers

Under Django 1.7 and above (thanks Colin Anderson):

from django.apps import apps apps.get_models() 

Under Django 1.6 and below.

If you want all models, try:

from django.db.models import get_models  for model in get_models():    # Do something with your model here    print model.__name__, [x.name for x in model._meta.fields] 

I believe the older function still works.

like image 180
Matthew Schinckel Avatar answered Sep 24 '22 08:09

Matthew Schinckel