netbox/docs/models
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
..
circuits Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
core add docs and tests 2026-03-10 08:58:07 -07:00
dcim Implement {module} position inheritance for nested module bays (#21753) 2026-04-01 17:58:16 -07:00
extras Closes #19025: Add schema validation for JSON custom fields (#21746) 2026-03-31 12:41:49 -05:00
ipam Closes #20698: Expose total_vlan_ids on VLAN groups (#21574) 2026-03-13 15:10:56 -05:00
tenancy 17170 Add ability to add contacts to multiple contact groups (#18885) 2025-03-18 14:05:02 -04:00
users Closes #20304: Object owners (#20634) 2025-10-24 13:08:01 -07:00
virtualization feat(virtualization): Add Virtual Machine Type model 2026-03-31 09:10:02 -04:00
vpn Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00
wireless Remove old "introduced in" notices 2025-08-01 15:57:26 -04:00