فهرست منبع

Closes #21261: add quick_add parameter to ObjectVar (#22271)

mburggraf 23 ساعت پیش
والد
کامیت
57e7884d83
2فایلهای تغییر یافته به همراه5 افزوده شده و 1 حذف شده
  1. 1 0
      docs/customization/custom-scripts.md
  2. 4 1
      netbox/extras/scripts.py

+ 1 - 0
docs/customization/custom-scripts.md

@@ -357,6 +357,7 @@ A particular object within NetBox. Each ObjectVar must specify a particular mode
 * `context` - A custom dictionary mapping template context variables to fields, used when rendering `<option>` elements within the dropdown menu (optional; see below)
 * `null_option` - A label representing a "null" or empty choice (optional)
 * `selector` - A boolean that, when True, includes an advanced object selection widget to assist the user in identifying the desired object (optional; False by default)
+* `quick_add` - A boolean that, when True, includes a quick add widget, to create a new related object for assignment. (optional; False by default)
 
 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:
 

+ 4 - 1
netbox/extras/scripts.py

@@ -234,10 +234,12 @@ class ObjectVar(ScriptVariable):
     :param null_option: The label to use as a "null" selection option (optional)
     :param selector: Include an advanced object selection widget to assist the user in identifying the desired
         object (optional)
+    :param quick_add: Include a widget to quickly create a new related object for assignment. (optional)
     """
     form_field = DynamicModelChoiceField
 
-    def __init__(self, model, query_params=None, context=None, null_option=None, selector=False, *args, **kwargs):
+    def __init__(self, model, query_params=None, context=None, null_option=None, selector=False, quick_add=False,
+                 *args, **kwargs):
         super().__init__(*args, **kwargs)
 
         self.field_attrs.update({
@@ -246,6 +248,7 @@ class ObjectVar(ScriptVariable):
             'context': context,
             'null_option': null_option,
             'selector': selector,
+            'quick_add': quick_add,
         })