I'm building a custom script with multiple fields that I want to pre-fill from a a URL (that I will generate from a Custom Link).
It works, except for MultiObjectVar (Multiple Select) variable type.
test = MultiObjectVar(
queryset=Device.objects.filter(status="active"),
required=True,
label="Test field",
)
Field should contain the value of ID in specified in URL parameter test (GET)
with step 1 and 2: It doesn't fill any field. MultiObjectVar is blank/null. No error.
With step 3, as a MultiObjectVar should contain a list object, it gives:
class 'ValueError'
invalid literal for int() with base 10: ']'
If I add "default=[1,2]" to step 1 MultiObjectVar, it will fill it with the right values.
"default", for this MultiObjectVar variable, needs a list object. int() will give an error.
If you replace MultiObjectVar with ObjectVar and repeat step 2, it will fill the field with the right value.
Filling fields from GET parameters seems to work for all other field type I tried.
We should be able to pass multiple values using GET requests for such field type.
Is ?test=[1,2] the syntax we want for this? I personally would prefer to make the brackets optional and also allow ?test=1,2 and ?test=1. Any objections to that?
Let’s try to keep it consistent between other API filters? I think the rest api requires test=1&test=2 to dictate an ‘or’ filter?
edit: https://github.com/netbox-community/netbox/issues/4313
edit: #4313
That makes the choice very clear :) Working on it!
Most helpful comment
Let’s try to keep it consistent between other API filters? I think the rest api requires test=1&test=2 to dictate an ‘or’ filter?
edit: https://github.com/netbox-community/netbox/issues/4313