Command
Overview
The base class from which all management commands ultimately derive.
Use this class if you want access to all of the mechanisms which parse the command-line arguments and work out what code to call in response; if you don't need to change any of that behavior, consider using one of the subclasses defined in this file.
If you are interested in overriding/customizing various aspects of the command-parsing and -execution behavior, the normal flow works as follows:
django-adminormanage.pyloads the command class and calls itsrun_from_argv()method.The
run_from_argv()method callscreate_parser()to get anArgumentParserfor the arguments, parses them, performs any environment changes requested by options likepythonpath, and then calls theexecute()method, passing the parsed arguments.The
execute()method attempts to carry out the command by calling thehandle()method with the parsed arguments; any output produced byhandle()will be printed to standard output and, if the command is intended to produce a block of SQL statements, will be wrapped inBEGINandCOMMIT.If
handle()orexecute()raised any exception (e.g.CommandError),run_from_argv()will instead print an error message tostderr.
Thus, the handle() method is typically the starting point for subclasses; many built-in commands and command types either place all of their logic in handle(), or perform some additional parsing work in handle() and then delegate from it to more specialized methods as needed.
Several attributes affect behavior at various steps along the way:
help A short description of the command, which will be printed in help messages.
output_transaction A boolean indicating whether the command outputs SQL statements; if True, the output will automatically be wrapped with BEGIN; and COMMIT;. Default value is False.
requires_migrations_checks A boolean; if True, the command prints a warning if the set of migrations on disk don't match the migrations in the database.
requires_system_checks A list or tuple of tags, e.g. [Tags.staticfiles, Tags.models]. System checks registered in the chosen tags will be checked for errors prior to executing the command. The value 'all' can be used to specify that all system checks should be performed. Default value is 'all'.
To validate an individual application's models
rather than all applications' models, call
``self.check(app_configs)`` from ``handle()``, where ``app_configs``
is the list of application's configuration provided by the
app registry.
stealth_options A tuple of any options the command uses which aren't defined by the argument parser.
_add_previously_matched_pk
Signature
_add_previously_matched_pk(self, obj, model_name)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| obj | yes | ||
| model_name | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1332
_convert_historical_change
Signature
_convert_historical_change(self, historical_change, content_type_id, model_name, workflow_model_field_names_to_attname)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| historical_change | yes | ||
| content_type_id | yes | ||
| model_name | yes | ||
| workflow_model_field_names_to_attname | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1824
_create_and_get_empty_migration
Signature
_create_and_get_empty_migration(self, app_label)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| app_label | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1960
_create_migration_per_app
Signature
_create_migration_per_app(self, changes_by_app)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| changes_by_app | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:2046
_get_apps_with_workflow
Signature
_get_apps_with_workflow(self, selected_apps)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| selected_apps | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1101
_get_content_type_for_model
Return the content type a change belongs to, or None when history cannot say.
A change in a migration file names its workflow by code. Nothing guarantees this database recorded that workflow: it may predate the event tables, or belong to a project the file was written against. Such a change simply matches nothing here.
Signature
_get_content_type_for_model(model_name, history_type, changed_item)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| model_name | yes | ||
| history_type | yes | ||
| changed_item | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1217
_get_generated_date_for_vueda_generated_migration
Signature
_get_generated_date_for_vueda_generated_migration(self, migration_path)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| migration_path | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1078
_get_historical_queryset_for_model
Return every recorded write for one workflow model, narrowed to one app's workflow.
The narrowing walks the event model's own foreign keys, which point at the live rows. When the workflow itself has been deleted that walk finds nothing, so each case falls back to the workflow's own recorded events to learn which rows belonged to it.
Signature
_get_historical_queryset_for_model(model_name, workflow_model, content_type_id)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| model_name | yes | ||
| workflow_model | yes | ||
| content_type_id | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1143
_get_history_compared_to_existing_changes
Signature
_get_history_compared_to_existing_changes(self, all_migrated_data, workflow_model_field_names_to_attname)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| all_migrated_data | yes | ||
| workflow_model_field_names_to_attname | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1511
_get_history_obj_from_change
Signature
_get_history_obj_from_change(self, model_name, changed_item, historical_queryset, workflow_model_field_names_to_attname)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| model_name | yes | ||
| changed_item | yes | ||
| historical_queryset | yes | ||
| workflow_model_field_names_to_attname | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1353
_get_history_record_at
Return a related row as it stood when the write being described was recorded.
A deleted row's closest record is the first event at or after that moment, which is the delete itself. A row that still exists is described by its last event at or before it. Which applies is not known here, so a delete found first wins and otherwise the earlier event does.
Ordering is by recorded time, not by event id: ids number each event table separately and this compares across two of them. Every event is stamped with clock_timestamp(), so writes inside one transaction still order.
Signature
_get_history_record_at(event_model, obj_id, recorded_at)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| event_model | yes | ||
| obj_id | yes | ||
| recorded_at | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1639
_get_vueda_generated_migration_data_per_app
Signature
_get_vueda_generated_migration_data_per_app(self, selected_apps)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| selected_apps | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1587
_parse_related_fields_into_changes_data
Signature
_parse_related_fields_into_changes_data(self, history_diff, historical_date, change, field_name, ct)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| history_diff | yes | ||
| historical_date | yes | ||
| change | yes | ||
| field_name | yes | ||
| ct | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1660
_recursive_compile_changed_item
Signature
_recursive_compile_changed_item(self, query, history_date)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| query | yes | ||
| history_date | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1284
_remove_previously_matched_pks
Signature
_remove_previously_matched_pks(self, queryset, model_name)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| queryset | yes | ||
| model_name | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1339
_replace_renamed_fields
Signature
_replace_renamed_fields(self, query, workflow_model_field_names_to_attname)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| query | yes | ||
| workflow_model_field_names_to_attname | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1345
_rewrite_migration
Signature
_rewrite_migration(self, migration_file, changed_data, app_label, migration_name, dependencies)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| migration_file | yes | ||
| changed_data | yes | ||
| app_label | yes | ||
| migration_name | yes | ||
| dependencies | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1997
add_arguments
Entry point for subclassed commands to add custom arguments.
Signature
add_arguments(self, parser)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| parser | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1030
add_renamed_fields_and_models_to_attr_names
Signature
add_renamed_fields_and_models_to_attr_names(self, workflow_model_field_names_to_attname)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| workflow_model_field_names_to_attname | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1492
clean_changes_by_app
Signature
clean_changes_by_app(self, changes)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| changes | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:2079
handle
The actual logic of the command. Subclasses must implement this method.
Signature
handle(self, app_labels, options)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| app_labels | yes | ||
| options | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:2147
print_debug
Signature
print_debug(self, debug_name, app_data)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| self | yes | ||
| debug_name | yes | ||
| app_data | yes |
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:2086
help
Source
server/vueda/workflow/management/commands/makeworkflowmigrations.py:1021