mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Moved 'display_name' from serializer to model
This commit is contained in:
@ -50,7 +50,6 @@ class RackGroupNestedSerializer(SiteSerializer):
|
||||
|
||||
|
||||
class RackSerializer(serializers.ModelSerializer):
|
||||
display_name = serializers.SerializerMethodField()
|
||||
site = SiteNestedSerializer()
|
||||
group = RackGroupNestedSerializer()
|
||||
|
||||
@ -58,9 +57,6 @@ class RackSerializer(serializers.ModelSerializer):
|
||||
model = Rack
|
||||
fields = ['id', 'name', 'facility_id', 'display_name', 'site', 'group', 'u_height', 'comments']
|
||||
|
||||
def get_display_name(self, obj):
|
||||
return str(obj)
|
||||
|
||||
|
||||
class RackNestedSerializer(RackSerializer):
|
||||
|
||||
|
@ -177,8 +177,6 @@ class Rack(models.Model):
|
||||
]
|
||||
|
||||
def __unicode__(self):
|
||||
if self.facility_id:
|
||||
return "{} ({})".format(self.name, self.facility_id)
|
||||
return self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
@ -197,6 +195,12 @@ class Rack(models.Model):
|
||||
def units(self):
|
||||
return reversed(range(1, self.u_height + 1))
|
||||
|
||||
@property
|
||||
def display_name(self):
|
||||
if self.facility_id:
|
||||
return "{} ({})".format(self.name, self.facility_id)
|
||||
return self.name
|
||||
|
||||
def get_rack_units(self, face=RACK_FACE_FRONT, remove_redundant=False):
|
||||
"""
|
||||
Return a list of rack units as dictionaries. Example: {'device': None, 'face': 0, 'id': 48, 'name': 'U48'}
|
||||
|
Reference in New Issue
Block a user