Custom Field Choices in custom script ObjectVar #18088
-
I am trying to create a custom script with an ObjectVar field which has the values of one of my custom field choice sets, but I can't figure out how to set the query_params to achieve it. from extras.models.customfields import CustomFieldChoiceSet
from extras.scripts import StringVar, ObjectVar, IPAddressWithMaskVar, Script
class NewPrinterScript(Script):
class Meta:
name = "New printer"
description = "Creates a new printer"
field_order = ['name','ip_address','win10driver']
name = StringVar(
description = "Printer Name"
)
ip_address = IPAddressWithMaskVar(
description = "IP address of the printer"
)
win10driver = ObjectVar(
description = "Windows 10 driver",
model = CustomFieldChoiceSet,
query_params={
'id':2
}
)
def run(self, data, commit):
return True |
Beta Was this translation helpful? Give feedback.
Answered by
Zombie-Toad
Nov 25, 2024
Replies: 1 comment
-
After a lot of trial an error I came up with this solution: from extras.models.customfields import CustomFieldChoiceSet
from extras.scripts import ChoiceVar, StringVar, ObjectVar, IPAddressWithMaskVar, Script
class NewPrinterScript(Script):
class Meta:
name = "New printer"
description = "Creates a new printer"
field_order = ['name','ip_address','win10driver']
win10drivers_list = CustomField.objects.get(id=2).choices
name = StringVar(
description = "Printer Name"
)
ip_address = IPAddressWithMaskVar(
description = "IP address of the printer"
)
win10driver = ChoiceVar(
description = "Windows 10 driver",
choices = win10drivers_list
)
def run(self, data, commit):
return True I don't know if this is the only way to implement custom field values to custom scripts, but it seems to work. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Zombie-Toad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After a lot of trial an error I came up with this solution: