-
NetBox versionv2.11.0 Python version3.7 Steps to ReproduceCreate a new script with a portion to create a new vlan with tags
The 3,9,16 are valid IDs for tags. Expected BehaviorA new vlan is created, with the 3 tags assigned to the vlan Observed BehaviorThe vlan is created, but no tags are seen on the vlan. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Tags use a many-to-many relationship, which is handled a bit differently from model fields. You'll need to save the new instance first, then call |
Beta Was this translation helpful? Give feedback.
-
Jeremy, Thank you for taking time to look into this. I have this code now : ` newvlan.tag.add(16) newvlan=VLAN.objects.get(vid=1234) But I still get the 'ipam.VLAN.None'. Really strange, it must be my coding skill I guess. Unfortunattely, I'm not able to find some good example Pieter |
Beta Was this translation helpful? Give feedback.
Jeremy,
Thank you for taking time to look into this.
I have this code now :
`
vlangroup=VLANGroup.objects.get(id=3)
newvid = '1234'
vlanname = "testvlan"
newvlan = VLAN(
vid = newvid,
name = vlanname,
group = vlangroup,
)
newvlan.save()
self.log_success(f"Vlan tags : {newvlan.tags}")
newvlan.tag.add(16)
newvlan.tag.add(9)
newvlan.tag.add(3)
newvlan.save()
newvlan=VLAN.objects.get(vid=1234)
self.log_success(f"Vlan tags : {newvlan.tags}")
`
But I still get the 'ipam.VLAN.None'.
Really strange, it must be my coding skill I guess. Unfortunattely, I'm not able to find some good example
Pieter