Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions netbox/ipam/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ class PrefixImportForm(ScopedImportForm, NetBoxModelImportForm):
to_field_name='name',
help_text=_("VLAN's group (if any)")
)
vlan_site = CSVModelChoiceField(
label=_('VLAN Site'),
queryset=Site.objects.all(),
required=False,
to_field_name='name',
help_text=_("VLAN's site (if any)")
)
vlan = CSVModelChoiceField(
label=_('VLAN'),
queryset=VLAN.objects.all(),
Expand All @@ -200,8 +207,8 @@ class PrefixImportForm(ScopedImportForm, NetBoxModelImportForm):
class Meta:
model = Prefix
fields = (
'prefix', 'vrf', 'tenant', 'vlan_group', 'vlan', 'status', 'role', 'scope_type', 'scope_id', 'is_pool',
'mark_utilized', 'description', 'comments', 'tags',
'prefix', 'vrf', 'tenant', 'vlan_group', 'vlan_site', 'vlan', 'status', 'role', 'scope_type', 'scope_id',
'is_pool', 'mark_utilized', 'description', 'comments', 'tags',
)
labels = {
'scope_id': _('Scope ID'),
Expand All @@ -213,19 +220,19 @@ def __init__(self, data=None, *args, **kwargs):
if not data:
return

site = data.get('site')
vlan_site = data.get('vlan_site')
vlan_group = data.get('vlan_group')

# Limit VLAN queryset by assigned site and/or group (if specified)
query = Q()

if site:
if vlan_site:
query |= Q(**{
f"site__{self.fields['site'].to_field_name}": site
f"site__{self.fields['vlan_site'].to_field_name}": vlan_site
})
# Don't Forget to include VLANs without a site in the filter
query |= Q(**{
f"site__{self.fields['site'].to_field_name}__isnull": True
f"site__{self.fields['vlan_site'].to_field_name}__isnull": True
})

if vlan_group:
Expand Down