Skip to content

Commit

Permalink
Closes netbox-community#292: Added part_number field to DeviceType
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jul 26, 2016
1 parent 9adeb48 commit 70a8dfd
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions netbox/dcim/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class DeviceTypeAdmin(admin.ModelAdmin):
InterfaceTemplateAdmin,
DeviceBayTemplateAdmin,
]
list_display = ['model', 'manufacturer', 'slug', 'u_height', 'console_ports', 'console_server_ports', 'power_ports',
'power_outlets', 'interfaces', 'device_bays']
list_display = ['model', 'manufacturer', 'slug', 'part_number', 'u_height', 'console_ports', 'console_server_ports',
'power_ports', 'power_outlets', 'interfaces', 'device_bays']
list_filter = ['manufacturer']

def get_queryset(self, request):
Expand Down
10 changes: 5 additions & 5 deletions netbox/dcim/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class DeviceTypeSerializer(serializers.ModelSerializer):

class Meta:
model = DeviceType
fields = ['id', 'manufacturer', 'model', 'slug', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu',
'is_network_device']
fields = ['id', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth',
'is_console_server', 'is_pdu', 'is_network_device']


class DeviceTypeNestedSerializer(DeviceTypeSerializer):
Expand Down Expand Up @@ -164,9 +164,9 @@ class DeviceTypeDetailSerializer(DeviceTypeSerializer):
interface_templates = InterfaceTemplateNestedSerializer(many=True, read_only=True)

class Meta(DeviceTypeSerializer.Meta):
fields = ['id', 'manufacturer', 'model', 'slug', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu',
'is_network_device', 'console_port_templates', 'cs_port_templates', 'power_port_templates',
'power_outlet_templates', 'interface_templates']
fields = ['id', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth',
'is_console_server', 'is_pdu', 'is_network_device', 'console_port_templates', 'cs_port_templates',
'power_port_templates', 'power_outlet_templates', 'interface_templates']


#
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class DeviceTypeFilter(django_filters.FilterSet):

class Meta:
model = DeviceType
fields = ['manufacturer_id', 'manufacturer', 'model', 'u_height', 'is_console_server', 'is_pdu',
fields = ['manufacturer_id', 'manufacturer', 'model', 'part_number', 'u_height', 'is_console_server', 'is_pdu',
'is_network_device']


Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class DeviceTypeForm(forms.ModelForm, BootstrapMixin):

class Meta:
model = DeviceType
fields = ['manufacturer', 'model', 'slug', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu',
fields = ['manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu',
'is_network_device', 'subdevice_role']


Expand Down
20 changes: 20 additions & 0 deletions netbox/dcim/migrations/0011_devicetype_part_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2016-07-26 15:05
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dcim', '0010_devicebay_installed_device_set_null'),
]

operations = [
migrations.AddField(
model_name='devicetype',
name='part_number',
field=models.CharField(blank=True, help_text=b'Discrete part number (optional)', max_length=50),
),
]
1 change: 1 addition & 0 deletions netbox/dcim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class DeviceType(models.Model):
manufacturer = models.ForeignKey('Manufacturer', related_name='device_types', on_delete=models.PROTECT)
model = models.CharField(max_length=50)
slug = models.SlugField()
part_number = models.CharField(max_length=50, blank=True, help_text="Discrete part number (optional)")
u_height = models.PositiveSmallIntegerField(verbose_name='Height (U)', default=1)
is_full_depth = models.BooleanField(default=True, verbose_name="Is full depth",
help_text="Device consumes both front and rear rack faces")
Expand Down
3 changes: 2 additions & 1 deletion netbox/dcim/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ class DeviceTypeTable(BaseTable):
pk = ToggleColumn()
manufacturer = tables.Column(verbose_name='Manufacturer')
model = tables.LinkColumn('dcim:devicetype', args=[Accessor('pk')], verbose_name='Device Type')
part_number = tables.Column(verbose_name='Part Number')

class Meta(BaseTable.Meta):
model = DeviceType
fields = ('pk', 'model', 'manufacturer', 'u_height')
fields = ('pk', 'model', 'manufacturer', 'part_number', 'u_height')


#
Expand Down
10 changes: 10 additions & 0 deletions netbox/templates/dcim/devicetype.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ <h1>{{ devicetype }}</h1>
<td>Model Name</td>
<td>{{ devicetype.model }}</td>
</tr>
<tr>
<td>Part Number</td>
<td>
{% if devicetype.part_number %}
{{ devicetype.part_number }}
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
</tr>
<tr>
<td>Height (U)</td>
<td>{{ devicetype.u_height }}</td>
Expand Down

0 comments on commit 70a8dfd

Please sign in to comment.