mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Add filter_fields to extras.ObjectVar & fix default value handling
This commit is contained in:
parent
e8b3d191e6
commit
52a1f9ddf0
@ -181,16 +181,19 @@ class ObjectVar(ScriptVariable):
|
||||
|
||||
:param model: The NetBox model being referenced
|
||||
:param query_params: A dictionary of additional query parameters to attach when making REST API requests (optional)
|
||||
:param filter_fields: A dictionary or list of dictionaries that define a related
|
||||
field. Example: `{'accessor': 'group_id', 'field_name': 'tenant_group'}` (optional)
|
||||
:param null_option: The label to use as a "null" selection option (optional)
|
||||
"""
|
||||
form_field = DynamicModelChoiceField
|
||||
|
||||
def __init__(self, model, query_params=None, null_option=None, *args, **kwargs):
|
||||
def __init__(self, model, query_params=None, filter_fields=None, null_option=None, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.field_attrs.update({
|
||||
'queryset': model.objects.all(),
|
||||
'query_params': query_params,
|
||||
'filter_fields': filter_fields,
|
||||
'null_option': null_option,
|
||||
})
|
||||
|
||||
|
@ -416,7 +416,7 @@ class DynamicModelChoiceMixin:
|
||||
widget.add_query_param(key, value)
|
||||
|
||||
# Attach any dynamic query parameters
|
||||
if len(self.filter_fields) > 0:
|
||||
if self.filter_fields is not None and len(self.filter_fields) > 0:
|
||||
widget.add_filter_fields(self.filter_fields)
|
||||
|
||||
return attrs
|
||||
|
Loading…
Reference in New Issue
Block a user