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