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:22:11 -04:00
parent 2866232b8b
commit f17938f156
4 changed files with 12 additions and 8 deletions

View File

@ -78,7 +78,6 @@ class AggregateNestedSerializer(AggregateSerializer):
#
class VLANSerializer(serializers.ModelSerializer):
display_name = serializers.SerializerMethodField()
site = SiteNestedSerializer()
role = RoleNestedSerializer()
@ -86,9 +85,6 @@ class VLANSerializer(serializers.ModelSerializer):
model = VLAN
fields = ['id', 'site', 'vid', 'name', 'status', 'role', 'display_name']
def get_display_name(self, obj):
return "{} ({})".format(obj.vid, obj.name)
class VLANNestedSerializer(VLANSerializer):

View File

@ -344,7 +344,7 @@ class VLAN(models.Model):
verbose_name_plural = 'VLANs'
def __unicode__(self):
return "{0} ({1})".format(self.vid, self.name)
return "VLAN {}".format(self.vid)
def get_absolute_url(self):
return reverse('ipam:vlan', args=[self.pk])
@ -358,5 +358,9 @@ class VLAN(models.Model):
self.role.name if self.role else '',
])
@property
def display_name(self):
return "{} ({})".format(self.vid, self.name)
def get_status_class(self):
return STATUS_CHOICE_CLASSES[self.status]

View File

@ -50,7 +50,7 @@
<td>VLAN</td>
<td>
{% if prefix.vlan %}
<a href="{% url 'ipam:vlan' pk=prefix.vlan.pk %}">{{ prefix.vlan.name }} ({{ prefix.vlan.vid }})</a>
<a href="{% url 'ipam:vlan' pk=prefix.vlan.pk %}">{{ prefix.vlan.display_name }}</a>
{% else %}
<span class="text-muted">Not assigned</span>
{% endif %}

View File

@ -1,7 +1,7 @@
{% extends '_base.html' %}
{% load render_table from django_tables2 %}
{% block title %}VLAN {{ vlan }}{% endblock %}
{% block title %}VLAN {{ vlan.display_name }}{% endblock %}
{% block content %}
<div class="row">
@ -55,6 +55,10 @@
<td>VLAN ID</td>
<td>{{ vlan.vid }}</td>
</tr>
<tr>
<td>Name</td>
<td>{{ vlan.name }}</td>
</tr>
<tr>
<td>Status</td>
<td>
@ -85,7 +89,7 @@
<a href="{% url 'dcim:site' slug=p.site.slug %}">{{ p.site }}</a>
{% endif %}
</td>
<td>{{ p.status }}</td>
<td>{{ p.get_status_display }}</td>
<td>{{ p.role }}</td>
</tr>
{% endfor %}