Skip to content

Commit

Permalink
Merge pull request #18444 from netbox-community/18433-fix-macaddress-…
Browse files Browse the repository at this point in the history
…primary-for-interface

Fixes: #18433 - Fix missing is_primary property on MACAddress model
  • Loading branch information
bctiemann authored Jan 27, 2025
2 parents 57fa1dd + ee5d7cf commit cf64f3c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions netbox/dcim/models/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,13 @@ def __init__(self, *args, **kwargs):
self._original_assigned_object_id = self.__dict__.get('assigned_object_id')
self._original_assigned_object_type_id = self.__dict__.get('assigned_object_type_id')

@cached_property
def is_primary(self):
if self.assigned_object and hasattr(self.assigned_object, 'primary_mac_address'):
if self.assigned_object.primary_mac_address and self.assigned_object.primary_mac_address.pk == self.pk:
return True
return False

def clean(self, *args, **kwargs):
super().clean()
if self._original_assigned_object_id and self._original_assigned_object_type_id:
Expand Down

0 comments on commit cf64f3c

Please sign in to comment.