Skip to content

Commit

Permalink
Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 12, 2024
1 parent 790aed2 commit 8bf7e90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions netbox/utilities/forms/fields/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class DynamicModelChoiceMixin:
selector: Include an advanced object selection widget to assist the user in identifying the desired object
quick_add: Include a widget to quickly create a new related object for assignment. NOTE: Nested usage of
quick-add fields is not currently supported.
quick_add_params: A dictionary of initial data to include when launching the quick-add form (optional). The
token string "$pk" will be replaced with the primary key of the form's instance, if any.
Context keys:
value: The name of the attribute which contains the option's value (default: 'id')
Expand Down Expand Up @@ -177,8 +179,11 @@ def get_bound_field(self, form, field_name):
}
for k, v in self.quick_add_params.items():
if v == '$pk':
v = form.instance.pk
widget.quick_add_context['params'][k] = v
# Replace "$pk" token with the primary key of the form's instance (if any)
if getattr(form.instance, 'pk', None):
widget.quick_add_context['params'][k] = form.instance.pk
else:
widget.quick_add_context['params'][k] = v

return bound_field

Expand Down
2 changes: 1 addition & 1 deletion netbox/utilities/forms/widgets/apiselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class APISelect(forms.Select):
def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)

# Add quick-add context data, if set on the widget
# Add quick-add context data, if enabled for the widget
if hasattr(self, 'quick_add_context'):
context['quick_add'] = self.quick_add_context

Expand Down

0 comments on commit 8bf7e90

Please sign in to comment.