Skip to content

Commit

Permalink
Merge pull request #95 from mlebreuil/89-need-to-link-contracts-to-vm…
Browse files Browse the repository at this point in the history
…-and-sites

add contract to vm
  • Loading branch information
mlebreuil authored Sep 3, 2023
2 parents d40cb76 + c952deb commit 1eb2f9a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/netbox_contract/template_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -45,4 +46,18 @@ def full_width_page(self):
'assignements_table': assignements_table,
})

template_extensions = [ CircuitContracts, CircuitContractAssignements, DeviceContractAssignements]
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]

0 comments on commit 1eb2f9a

Please sign in to comment.