Skip to content

Commit d0208d4

Browse files
committed
Update ObjectVar docs to reflect new filter_fields attribute
1 parent 52a1f9d commit d0208d4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/customization/custom-scripts.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ A particular object within NetBox. Each ObjectVar must specify a particular mode
171171

172172
* `model` - The model class
173173
* `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)
174175
* `null_option` - A label representing a "null" or empty choice (optional)
175176

176177
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(
184185
)
185186
```
186187

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:
188191

189192
```python
190193
region = ObjectVar(
191194
model=Region
192195
)
193196
site = ObjectVar(
194197
model=Site,
195-
query_params={
196-
'region_id': '$region'
198+
filter_fields={
199+
'accessor': 'region_id',
200+
'field_name': 'region',
197201
}
198202
)
199203
```
200204

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+
201207
### MultiObjectVar
202208

203209
Similar to `ObjectVar`, but allows for the selection of multiple objects.

0 commit comments

Comments
 (0)