1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #2229: Allow mapping of ConfigContexts to tenant groups

This commit is contained in:
Jeremy Stretch
2018-07-27 15:47:29 -04:00
parent 7476f522e1
commit a1e8397b6b
6 changed files with 29 additions and 10 deletions

View File

@ -13,6 +13,9 @@ class ConfigContextQuerySet(QuerySet):
# `device_role` for Device; `role` for VirtualMachine
role = getattr(obj, 'device_role', None) or obj.role
# Get the group of the assigned tenant, if any
tenant_group = obj.tenant.group if obj.tenant else None
# Match against the directly assigned region as well as any parent regions.
region = getattr(obj.site, 'region', None)
if region:
@ -24,7 +27,8 @@ class ConfigContextQuerySet(QuerySet):
Q(regions__in=regions) | Q(regions=None),
Q(sites=obj.site) | Q(sites=None),
Q(roles=role) | Q(roles=None),
Q(tenants=obj.tenant) | Q(tenants=None),
Q(platforms=obj.platform) | Q(platforms=None),
Q(tenant_groups=tenant_group) | Q(tenant_groups=None),
Q(tenants=obj.tenant) | Q(tenants=None),
is_active=True,
).order_by('weight', 'name')