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

Introduced CableTermination abstract model to ptovide Cable access from termination points

This commit is contained in:
Jeremy Stretch
2018-10-25 15:21:16 -04:00
parent 266429101b
commit f134a6ec63
5 changed files with 68 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
from django.db.models import QuerySet
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q, QuerySet
from django.db.models.expressions import RawSQL
from .constants import IFACE_ORDERING_NAME, IFACE_ORDERING_POSITION, NONCONNECTABLE_IFACE_TYPES
@@ -68,3 +69,16 @@ class InterfaceQuerySet(QuerySet):
wireless).
"""
return self.exclude(form_factor__in=NONCONNECTABLE_IFACE_TYPES)
class CableQuerySet(QuerySet):
def get_for_termination(self, termination):
"""
Return the Cable (or None) connected to a given termination point.
"""
content_type = ContentType.objects.get_for_model(termination)
return self.filter(
Q(termination_a_type=content_type, termination_a_id=termination.pk) |
Q(termination_b_type=content_type, termination_b_id=termination.pk)
).first()