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
Copy file name to clipboardExpand all lines: docs/customization/custom-scripts.md
+9-3
Original file line number
Diff line number
Diff line change
@@ -171,6 +171,7 @@ A particular object within NetBox. Each ObjectVar must specify a particular mode
171
171
172
172
*`model` - The model class
173
173
*`query_params` - A dictionary of query parameters to use when retrieving available options (optional)
174
+
*`filter_fields` - A dictionary or list of dictionaries that define a related field (optional)
174
175
*`null_option` - A label representing a "null" or empty choice (optional)
175
176
176
177
To limit the selections available within the list, additional query parameters can be passed as the `query_params` dictionary. For example, to show only devices with an "active" status:
@@ -184,20 +185,25 @@ device = ObjectVar(
184
185
)
185
186
```
186
187
187
-
Multiple values can be specified by assigning a list to the dictionary key. It is also possible to reference the value of other fields in the form by prepending a dollar sign (`$`) to the variable's name.
188
+
Multiple values can be specified by assigning a list to the dictionary key.
189
+
190
+
It is also possible to reference the value of other fields in the form by using the `filter_fields` attribute. For example, to only show sites matching the selected region:
188
191
189
192
```python
190
193
region = ObjectVar(
191
194
model=Region
192
195
)
193
196
site = ObjectVar(
194
197
model=Site,
195
-
query_params={
196
-
'region_id': '$region'
198
+
filter_fields={
199
+
'accessor': 'region_id',
200
+
'field_name': 'region',
197
201
}
198
202
)
199
203
```
200
204
205
+
In this example, `accessor` refers to the `region_id` field on the `Site` model, and `field_name` refers to form field name of the `Region` model.
206
+
201
207
### MultiObjectVar
202
208
203
209
Similar to `ObjectVar`, but allows for the selection of multiple objects.
0 commit comments