You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Add-button on Typed tabs with reverse-reference prefill (closes#9)
Each typed tab now exposes an "Add <Type>" button that links to the native
customobject_add view with the back-reference field pre-populated to the
parent object's PK and return_url set to the current tab path. After saving,
the user lands back on the tab with filters preserved.
When a Custom Object Type has multiple back-reference fields to the same
parent model (e.g. primary_device + backup_device both -> dcim.device),
the button becomes a Bootstrap split-dropdown listing each field. The
button is hidden for users without add_customobject permission.
Implementation:
- New module-level _build_add_links() helper computes URLs from
(slug, instance_pk, field_infos, return_url). Pure function, fully unit-tested.
- field_infos tuples extended from (name, type) to (name, type, label) so the
dropdown can show human-readable field labels. Star-unpacking in
_count_for_type and the queryset filter loop preserves backward compatibility
with 2-tuple shapes used by existing tests.
- Permission gate uses utilities.permissions.get_permission_for_model, matching
the pattern used by netbox_custom_objects.tables.CustomObjectActionsColumn.
- field_infos is sorted by field name in register_typed_tabs so the dropdown
order is deterministic.
Tab placement: top-right of tab content, scoped entirely to typed/tab.html.
Tabs with hide_if_empty=True remain hidden until the first object is created
via the native menu - the button surfaces once the tab is visible.
Bumps version to 2.2.0 (minor, new feature). Test suite extended from 53 to 61
tests covering reverse failure, single/multi field, deduplication, label
fallback, 2-tuple back-compat, and return_url URL-encoding.
0 commit comments