MCPcopy
hub / github.com/django/django / parse_apps_and_model_labels

Function parse_apps_and_model_labels

django/core/management/utils.py:89–113  ·  view source on GitHub ↗

Parse a list of "app_label.ModelName" or "app_label" strings into actual objects and return a two-element tuple: (set of model classes, set of app_configs). Raise a CommandError if some specified models or apps don't exist.

(labels)

Source from the content-addressed store, hash-verified

87
88
89def parse_apps_and_model_labels(labels):
90 """
91 Parse a list of "app_label.ModelName" or "app_label" strings into actual
92 objects and return a two-element tuple:
93 (set of model classes, set of app_configs).
94 Raise a CommandError if some specified models or apps don't exist.
95 """
96 apps = set()
97 models = set()
98
99 for label in labels:
100 if "." in label:
101 try:
102 model = installed_apps.get_model(label)
103 except LookupError:
104 raise CommandError("Unknown model: %s" % label)
105 models.add(model)
106 else:
107 try:
108 app_config = installed_apps.get_app_config(label)
109 except LookupError as e:
110 raise CommandError(str(e))
111 apps.add(app_config)
112
113 return models, apps
114
115
116def get_command_line_option(argv, option):

Callers 2

handleMethod · 0.90
handleMethod · 0.90

Calls 4

CommandErrorClass · 0.85
get_app_configMethod · 0.80
get_modelMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected