mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
exposes all models in device context data #12814
This commit is contained in:
parent
53615944c5
commit
7a953fa5ef
@ -1,3 +1,4 @@
|
||||
from django.apps import apps
|
||||
from django.http import Http404, HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
@ -23,6 +24,7 @@ from netbox.api.renderers import TextRenderer
|
||||
from netbox.api.viewsets import NetBoxModelViewSet
|
||||
from netbox.api.viewsets.mixins import SequentialBulkCreatesMixin
|
||||
from netbox.constants import NESTED_SERIALIZER_PREFIX
|
||||
from netbox.registry import registry
|
||||
from utilities.api import get_serializer_for_model
|
||||
from utilities.utils import count_related
|
||||
from virtualization.models import VirtualMachine
|
||||
@ -432,7 +434,15 @@ class DeviceViewSet(
|
||||
# Compile context data
|
||||
context_data = device.get_config_context()
|
||||
context_data.update(request.data)
|
||||
context_data.update({'device': device})
|
||||
context_data.update({'object': device})
|
||||
|
||||
app_ns = registry['model_features']['custom_fields'].keys()
|
||||
for app in app_ns:
|
||||
models = apps.get_app_config(app).get_models()
|
||||
for model in models:
|
||||
context_data.update({
|
||||
model.__name__: model
|
||||
})
|
||||
|
||||
return self.render_configtemplate(request, configtemplate, context_data)
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import traceback
|
||||
|
||||
from django.apps import apps
|
||||
from django.contrib import messages
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.paginator import EmptyPage, PageNotAnInteger
|
||||
@ -19,6 +20,7 @@ from circuits.models import Circuit, CircuitTermination
|
||||
from extras.views import ObjectConfigContextView
|
||||
from ipam.models import ASN, IPAddress, Prefix, VLAN, VLANGroup
|
||||
from ipam.tables import InterfaceVLANTable
|
||||
from netbox.registry import registry
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.forms import ConfirmationForm
|
||||
@ -2078,7 +2080,15 @@ class DeviceRenderConfigView(generic.ObjectView):
|
||||
def get_extra_context(self, request, instance):
|
||||
# Compile context data
|
||||
context_data = instance.get_config_context()
|
||||
context_data.update({'device': instance})
|
||||
context_data.update({'object': instance})
|
||||
|
||||
app_ns = registry['model_features']['custom_fields'].keys()
|
||||
for app in app_ns:
|
||||
models = apps.get_app_config(app).get_models()
|
||||
for model in models:
|
||||
context_data.update({
|
||||
model.__name__: model
|
||||
})
|
||||
|
||||
# Render the config template
|
||||
rendered_config = None
|
||||
|
Loading…
Reference in New Issue
Block a user