Merge pull request #4258 from netbox-community/4255-dynamic_object_vars

Fixes: #4255 - Modify script ObjectVars to utilize DynamicModelChoiceField
This commit is contained in:
Jeremy Stretch 2020-03-19 11:02:07 -04:00 committed by GitHub
commit 2dff093305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ from ipam.formfields import IPAddressFormField, IPNetworkFormField
from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator from ipam.validators import MaxPrefixLengthValidator, MinPrefixLengthValidator, prefix_validator
from .constants import LOG_DEFAULT, LOG_FAILURE, LOG_INFO, LOG_SUCCESS, LOG_WARNING from .constants import LOG_DEFAULT, LOG_FAILURE, LOG_INFO, LOG_SUCCESS, LOG_WARNING
from utilities.exceptions import AbortTransaction from utilities.exceptions import AbortTransaction
from utilities.forms import DynamicModelChoiceField, DynamicModelMultipleChoiceField
from .forms import ScriptForm from .forms import ScriptForm
from .signals import purge_changelog from .signals import purge_changelog
@ -167,7 +168,7 @@ class ObjectVar(ScriptVariable):
""" """
NetBox object representation. The provided QuerySet will determine the choices available. NetBox object representation. The provided QuerySet will determine the choices available.
""" """
form_field = forms.ModelChoiceField form_field = DynamicModelChoiceField
def __init__(self, queryset, *args, **kwargs): def __init__(self, queryset, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -184,7 +185,7 @@ class MultiObjectVar(ScriptVariable):
""" """
Like ObjectVar, but can represent one or more objects. Like ObjectVar, but can represent one or more objects.
""" """
form_field = forms.ModelMultipleChoiceField form_field = DynamicModelMultipleChoiceField
def __init__(self, queryset, *args, **kwargs): def __init__(self, queryset, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)