netbox/docs/models/dcim
Mark Robert Coleman a06a300913
Implement {module} position inheritance for nested module bays (#21753)
* Implement {module} position inheritance for nested module bays (#19796)

Enables a single ModuleType to produce correctly named components at any
nesting depth by resolving {module} in module bay position fields during
tree traversal. The user controls the separator through the position
field template itself (e.g. {module}/1 vs {module}-1 vs {module}.1).

Model layer:
- Add _get_inherited_positions() to resolve {module} in positions as
  the module tree is walked from root to leaf
- Update _resolve_module_placeholder() with single-token logic: one
  {module} resolves to the leaf bay's inherited position; multi-token
  continues level-by-level replacement for backwards compatibility

Form layer:
- Update _get_module_bay_tree() to resolve {module} in positions during
  traversal, propagating parent positions through the tree
- Extract validation into _validate_module_tokens() private method

Tests:
- Position inheritance at depth 2 and 3
- Custom separator (dot notation)
- Multi-token backwards compatibility
- Documentation for position inheritance

Fixes: #19796

* Consolidate {module} placeholder logic into shared utilities and add API validation

Extract get_module_bay_positions() and resolve_module_placeholder() into
dcim/utils.py as shared routines used by the model, form, and API serializer.
This eliminates duplicated traversal and resolution logic across three layers.

Key changes:
- Add position inheritance: {module} tokens in bay position fields resolve
  using the parent bay's position during hierarchy traversal
- Single {module} token now resolves to the leaf bay's inherited position
- Mismatched token count vs tree depth now raises ValueError instead of
  silently producing partial strings
- API serializer validation uses shared utilities for parity with the form
- Fix error message wording ("levels deep" instead of "in tree")
2026-04-01 17:58:16 -07:00
..
cable.md Closes #20788: Cable profiles and and position mapping (#20802) 2025-11-25 12:18:15 -06:00
cablebundle.md Closes #20151: Add support for cable bundles (#21636) 2026-03-11 11:43:40 -05:00
consoleport.md Update model docs for device components 2022-08-15 11:57:38 -04:00
consoleporttemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
consoleserverport.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
consoleserverporttemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
device.md Closes #15292: Remove obsolete device_role attribute from Device model 2024-03-01 11:31:47 -05:00
devicebay.md feat(dcim): Add enabled field to Module and Device bays 2026-03-11 20:51:23 +01:00
devicebaytemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
devicerole.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
devicetype.md Closes #21575: Implement `{vc_position}` template variable on component template name/label (#21601) 2026-03-18 10:15:11 -07:00
frontport.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
frontporttemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
interface.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
interfacetemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
inventoryitem.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
inventoryitemrole.md Closes #19004: Mark inventory items as deprecated in the documentation 2025-04-03 14:49:54 -04:00
inventoryitemtemplate.md Closes #19004: Mark inventory items as deprecated in the documentation 2025-04-03 14:49:54 -04:00
location.md Closes: #13918 - Add facility field (#15456) 2024-03-18 10:09:50 -04:00
macaddress.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
manufacturer.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
module.md Closes #10371: Add operational status field for modules 2022-12-09 10:43:29 -05:00
modulebay.md feat(dcim): Add enabled field to Module and Device bays 2026-03-11 20:51:23 +01:00
modulebaytemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
moduletype.md Implement {module} position inheritance for nested module bays (#21753) 2026-04-01 17:58:16 -07:00
moduletypeprofile.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
platform.md Closes #19740: Enable recursive nesting for platforms 2025-08-07 16:19:24 -04:00
powerfeed.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
poweroutlet.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
poweroutlettemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
powerpanel.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
powerport.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
powerporttemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
rack.md Closes #20961: Introduce RackGroup for physical rack placement (#21624) 2026-03-10 10:19:12 -05:00
rackgroup.md Closes #20961: Introduce RackGroup for physical rack placement (#21624) 2026-03-10 10:19:12 -05:00
rackreservation.md Closes #19034: Add calculated `RackReservation.unit_count`, with min/max filtering (#21665) 2026-03-25 08:50:53 -05:00
rackrole.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
racktype.md Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
rearport.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
rearporttemplate.md Update model docs for device components 2022-08-15 11:57:38 -04:00
region.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
site.md Closes #10820: Switch timezone library from pytz to zoneinfo 2022-11-02 15:54:41 -04:00
sitegroup.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
virtualchassis.md Finish refreshing DCIM models documentation 2022-08-15 15:16:02 -04:00
virtualdevicecontext.md Changelog & documentation for #7854 2022-11-11 08:25:44 -05:00