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

Add GenericRelation to originating cable paths on PathEndpoint

This commit is contained in:
Jeremy Stretch
2020-10-01 11:30:03 -04:00
parent 46df5a97b2
commit 19a3a4d4ef
8 changed files with 50 additions and 87 deletions

View File

@ -252,15 +252,19 @@ class CableTermination(models.Model):
return endpoints
class PathEndpoint:
class PathEndpoint(models.Model):
"""
Any object which may serve as either endpoint of a CablePath.
"""
paths = GenericRelation(
to='dcim.CablePath',
content_type_field='origin_type',
object_id_field='origin_id',
related_query_name='%(class)s'
)
def get_connections(self):
from dcim.models import CablePath
return CablePath.objects.filter(
origin_type=ContentType.objects.get_for_model(self),
origin_id=self.pk,
destination_id__isnull=False
)
class Meta:
abstract = True
#