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 ?
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.
In your settings.py file, you will find INSTALLED_APPS. Apps listed in INSTALLED_APPS are provided by Django for the developer's comfort.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With