1
0
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:
Jeremy Stretch
2016-06-21 15:06:26 -04:00
parent 72f62f949d
commit 658a0acfa9
2 changed files with 6 additions and 6 deletions

View File

@ -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):

View File

@ -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'}