Is your feature request related to a problem? Please describe.
Currently, each command execution is stored independently in the Command model, but there is no relationship between individual command executions and the mass operation that triggered them.
With the introduction of mass command execution, multiple Command objects will be created as part of a single MassCommand operation. Without an explicit relationship between these models, it would not be possible to identify from the device command history whether a command was executed individually or as part of a mass operation.
Describe the solution I would implement
I would like to add a relationship between Command and MassCommand by introducing a nullable foreign key in AbstractCommand.
mass_command = models.ForeignKey(
get_model_name("connection", "MassCommand"),
null=True,
blank=True,
on_delete=models.SET_NULL,
)
- Add a nullable mass_command foreign key field to AbstractCommand so that commands created as part of a batch operation can reference their parent MassCommand.
- Commands executed individually through the existing single-device workflow will continue to have this field set to NULL.
- On the device detail page, the command history should indicate whether a command was executed as part of a mass operation.
- If a command belongs to a MassCommand, the UI should provide a link to the corresponding mass command execution result page, allowing administrators to navigate directly to the parent batch operation.
Details to preserve during implementation
The device detail page integration should explicitly cover the Recent Commands section mentioned in the proposal. Commands created by a MassCommand should be visible there with enough context to show they belong to a parent mass operation.
The deletion behavior should be coordinated with the REST API and lifecycle work in #1349. The currently proposed on_delete=models.SET_NULL preserves child Command records but removes the parent link if the MassCommand is deleted. Possible approaches to investigate include allowing deletion and losing the parent link, protecting MassCommand deletion while child commands exist, soft-deleting or archiving MassCommand records, or another lifecycle rule that preserves traceability.
Automated tests should cover the nullable mass_command relation, single-device commands keeping this field set to NULL, command history rendering, and navigation from a command history entry to the parent MassCommand when applicable.
Is your feature request related to a problem? Please describe.
Currently, each command execution is stored independently in the Command model, but there is no relationship between individual command executions and the mass operation that triggered them.
With the introduction of mass command execution, multiple Command objects will be created as part of a single MassCommand operation. Without an explicit relationship between these models, it would not be possible to identify from the device command history whether a command was executed individually or as part of a mass operation.
Describe the solution I would implement
I would like to add a relationship between Command and MassCommand by introducing a nullable foreign key in AbstractCommand.
Details to preserve during implementation
The device detail page integration should explicitly cover the
Recent Commandssection mentioned in the proposal. Commands created by a MassCommand should be visible there with enough context to show they belong to a parent mass operation.The deletion behavior should be coordinated with the REST API and lifecycle work in #1349. The currently proposed
on_delete=models.SET_NULLpreserves child Command records but removes the parent link if the MassCommand is deleted. Possible approaches to investigate include allowing deletion and losing the parent link, protecting MassCommand deletion while child commands exist, soft-deleting or archiving MassCommand records, or another lifecycle rule that preserves traceability.Automated tests should cover the nullable
mass_commandrelation, single-device commands keeping this field set toNULL, command history rendering, and navigation from a command history entry to the parent MassCommand when applicable.