Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #11991 - Add vdcs to InterfaceImportForm and InterfaceBulkEditForm #11996

Merged

Conversation

kkthxbye-code
Copy link
Contributor

Fixes: #11991

Add vdcs to InterfaceImportForm and InterfaceBulkEditForm

@kkthxbye-code kkthxbye-code force-pushed the 11991-add-vdcs-if-bulk branch from cf3b922 to 80f9bd4 Compare March 16, 2023 21:04
@kkthxbye-code
Copy link
Contributor Author

kkthxbye-code commented Mar 16, 2023

I just realized that for the bulk import, the name cannot actually be used as the to_field_name value as it is not unique (two vdcs can have the same name if they are on different devices).

Not sure if there are other options than using ids instead?

@jeremystretch
Copy link
Member

Not sure if there are other options than using ids instead?

We'll need to extend the init method of InterfaceImportForm to automatically set the queryset of of the vdcs fields as we do for several other relationships:

if data:
# Limit choices for parent, bridge, and LAG interfaces to the assigned device
if device := data.get('device'):
params = {
f"device__{self.fields['device'].to_field_name}": device
}
self.fields['parent'].queryset = self.fields['parent'].queryset.filter(**params)
self.fields['bridge'].queryset = self.fields['bridge'].queryset.filter(**params)
self.fields['lag'].queryset = self.fields['lag'].queryset.filter(**params)

@kkthxbye-code
Copy link
Contributor Author

@jeremystretch - Fixed, thanks for the pointer!

@jeremystretch jeremystretch merged commit b12551c into netbox-community:develop Mar 28, 2023
jeremystretch pushed a commit that referenced this pull request Mar 28, 2023
…orm (#11996)

* Add vdcs to InterfaceImportForm and InterfaceBulkEditForm

* Filter vdcs queryset by device when bulk importing interfaces
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add VDC selection to Bulk Edit of interfaces and interface imports
2 participants