diff --git a/src/netbox_contract/api/serializers.py b/src/netbox_contract/api/serializers.py index 1acde4f..c4d296c 100644 --- a/src/netbox_contract/api/serializers.py +++ b/src/netbox_contract/api/serializers.py @@ -17,7 +17,7 @@ class Meta: model = ServiceProvider fields = ('id', 'url', 'display', 'name') -class NestedContracSerializer(WritableNestedSerializer): +class NestedContractSerializer(WritableNestedSerializer): url = serializers.HyperlinkedIdentityField( view_name='plugins-api:netbox_contract-api:contract-detail' ) @@ -50,7 +50,7 @@ class ContractSerializer(NetBoxModelSerializer): ) #circuit= NestedCircuitSerializer(many=True, required=False) external_partie = NestedServiceProviderSerializer(many=False) - parent = NestedContracSerializer(many=False, required=False) + parent = NestedContractSerializer(many=False, required=False) tenant= NestedTenantSerializer(many=False, required=False) class Meta: @@ -66,7 +66,7 @@ class InvoiceSerializer(NetBoxModelSerializer): url = serializers.HyperlinkedIdentityField( view_name='plugins-api:netbox_contract-api:invoice-detail' ) - contracts = NestedContracSerializer(many=True, required=False) + contracts = NestedContractSerializer(many=True, required=False) class Meta: model = Invoice @@ -95,7 +95,7 @@ class ContractAssignementSerializer(NetBoxModelSerializer): queryset=ContentType.objects.all() ) content_object = serializers.SerializerMethodField(read_only=True) - contract = NestedContracSerializer() + contract = NestedContractSerializer() class Meta: model = ContractAssignement diff --git a/src/netbox_contract/template_content.py b/src/netbox_contract/template_content.py index 8de34c4..0e3339b 100644 --- a/src/netbox_contract/template_content.py +++ b/src/netbox_contract/template_content.py @@ -2,6 +2,7 @@ from extras.plugins import PluginTemplateExtension from circuits.models import Circuit from dcim.models import Device +from virtualization.models import VirtualMachine from .models import ContractAssignement from . import tables @@ -45,4 +46,18 @@ def full_width_page(self): 'assignements_table': assignements_table, }) -template_extensions = [ CircuitContracts, CircuitContractAssignements, DeviceContractAssignements] \ No newline at end of file +class VMContractAssignements(PluginTemplateExtension): + model = 'virtualization.virtualmachine' + + def full_width_page(self): + device = self.context['object'] + device_type = ContentType.objects.get_for_model(VirtualMachine) + contract_assignements = ContractAssignement.objects.filter(content_type__pk=device_type.id, object_id=device.id) + assignements_table = tables.ContractAssignementObjectTable(contract_assignements) + assignements_table.configure(self.context['request']) + + return self.render('contract_assignements_bottom.html', extra_context={ + 'assignements_table': assignements_table, + }) + +template_extensions = [ CircuitContracts, CircuitContractAssignements, DeviceContractAssignements, VMContractAssignements] \ No newline at end of file diff --git a/src/netbox_contract/templates/netbox_contract/contract.html b/src/netbox_contract/templates/netbox_contract/contract.html index 19981bd..8e43e8d 100644 --- a/src/netbox_contract/templates/netbox_contract/contract.html +++ b/src/netbox_contract/templates/netbox_contract/contract.html @@ -1,4 +1,5 @@ {% extends 'generic/object.html' %} +{% load plugins %} {% load render_table from django_tables2 %} {% block breadcrumbs %} {{ block.super }} @@ -137,4 +138,5 @@