def get_models(app_labels): """ Gets a list of models for the given app labels, with some exceptions. TODO: If a required model is referenced, it should also be included. Or at least discovered with a get_or_create() call. """ from django.db.models import get_app, get_apps, get_model from django.db.models import get_models as get_all_models # These models are not to be output, e.g. because they can be generated automatically # TODO: This should be "appname.modelname" string EXCLUDED_MODELS = (ContentType, ) models = [] # If no app labels are given, return all if not app_labels: for app in get_apps(): models += [m for m in get_all_models(app) if m not in EXCLUDED_MODELS] # Get all relevant apps for app_label in app_labels: # If a specific model is mentioned, get only that model if "." in app_label: app_label, model_name = app_label.split(".", 1) models.append(get_model(app_label, model_name)) # Get all models for a given app else: models += [m for m in get_all_models(get_app(app_label)) if m not in EXCLUDED_MODELS] return models
def get_models(app_labels): """ Gets a list of models for the given app labels. Modified from dumpscript.py """ from django.db.models import get_app, get_apps, get_model from django.db.models import get_models as get_all_models models = [] # If no app labels are given, return all if not app_labels: for app in get_apps(): models.extend(get_all_models(app)) # Get all relevant apps for app_label in app_labels: # If a specific model is mentioned, get only that model if "." in app_label: app_label, model_name = app_label.split(".", 1) models.append(get_model(app_label, model_name)) # Get all models for a given app else: models.extend(get_all_models(get_app(app_label))) return models
def get_models(app_labels): """ Gets a list of models for the given app labels, with some exceptions. """ from django.db.models import get_app, get_apps from django.db.models import get_models as get_all_models # These models are not to be output, e.g. because they can be generated automatically # TODO: This should also specify the app, in case model # EXCLUDED_MODELS = ('') # Change tried during attempt to dump contenttypes EXCLUDED_MODELS = ('ContentType') # Get all relevant apps if not app_labels: app_list = get_apps() else: app_list = [ get_app(app_label) for app_label in app_labels ] # Get a list of all the relevant models models = [] for app in app_list: # Get all models for each app, except any excluded ones models += [ m for m in get_all_models(app) if m.__name__ not in EXCLUDED_MODELS ] return models