(self, *app_labels, **options)
| 102 | ) |
| 103 | |
| 104 | def handle(self, *app_labels, **options): |
| 105 | format = options["format"] |
| 106 | indent = options["indent"] |
| 107 | using = options["database"] |
| 108 | excludes = options["exclude"] |
| 109 | output = options["output"] |
| 110 | show_traceback = options["traceback"] |
| 111 | use_natural_foreign_keys = options["use_natural_foreign_keys"] |
| 112 | use_natural_primary_keys = options["use_natural_primary_keys"] |
| 113 | use_base_manager = options["use_base_manager"] |
| 114 | pks = options["primary_keys"] |
| 115 | |
| 116 | if pks: |
| 117 | primary_keys = [pk.strip() for pk in pks.split(",")] |
| 118 | else: |
| 119 | primary_keys = [] |
| 120 | |
| 121 | excluded_models, excluded_apps = parse_apps_and_model_labels(excludes) |
| 122 | |
| 123 | if not app_labels: |
| 124 | if primary_keys: |
| 125 | raise CommandError("You can only use --pks option with one model") |
| 126 | app_list = dict.fromkeys( |
| 127 | app_config |
| 128 | for app_config in apps.get_app_configs() |
| 129 | if app_config.models_module is not None |
| 130 | and app_config not in excluded_apps |
| 131 | ) |
| 132 | else: |
| 133 | if len(app_labels) > 1 and primary_keys: |
| 134 | raise CommandError("You can only use --pks option with one model") |
| 135 | app_list = {} |
| 136 | for label in app_labels: |
| 137 | try: |
| 138 | app_label, model_label = label.split(".") |
| 139 | try: |
| 140 | app_config = apps.get_app_config(app_label) |
| 141 | except LookupError as e: |
| 142 | raise CommandError(str(e)) |
| 143 | if app_config.models_module is None or app_config in excluded_apps: |
| 144 | continue |
| 145 | try: |
| 146 | model = app_config.get_model(model_label) |
| 147 | except LookupError: |
| 148 | raise CommandError( |
| 149 | "Unknown model: %s.%s" % (app_label, model_label) |
| 150 | ) |
| 151 | |
| 152 | app_list_value = app_list.setdefault(app_config, []) |
| 153 | |
| 154 | # We may have previously seen an "all-models" request for |
| 155 | # this app (no model qualifier was given). In this case |
| 156 | # there is no need adding specific models to the list. |
| 157 | if app_list_value is not None and model not in app_list_value: |
| 158 | app_list_value.append(model) |
| 159 | except ValueError: |
| 160 | if primary_keys: |
| 161 | raise CommandError( |
nothing calls this directly
no test coverage detected