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)
| 87 | |
| 88 | |
| 89 | def 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 | |
| 116 | def get_command_line_option(argv, option): |
no test coverage detected