mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Closes #1444: Add field to Rack model
This commit is contained in:
parent
d4ec309d68
commit
4ffe1866c5
@ -7,6 +7,7 @@ v2.5.0 (FUTURE)
|
|||||||
|
|
||||||
## Enhancements
|
## Enhancements
|
||||||
|
|
||||||
|
* [#1444](https://github.com/digitalocean/netbox/issues/1444) - Added an `asset_tag` field for racks
|
||||||
* [#2000](https://github.com/digitalocean/netbox/issues/2000) - Dropped support for Python 2
|
* [#2000](https://github.com/digitalocean/netbox/issues/2000) - Dropped support for Python 2
|
||||||
* [#2104](https://github.com/digitalocean/netbox/issues/2104) - Added a `status` field for racks
|
* [#2104](https://github.com/digitalocean/netbox/issues/2104) - Added a `status` field for racks
|
||||||
* [#2292](https://github.com/digitalocean/netbox/issues/2292) - Removed the deprecated UserAction model
|
* [#2292](https://github.com/digitalocean/netbox/issues/2292) - Removed the deprecated UserAction model
|
||||||
|
@ -126,8 +126,9 @@ class RackSerializer(TaggitSerializer, CustomFieldModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Rack
|
model = Rack
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'name', 'facility_id', 'display_name', 'site', 'group', 'tenant', 'status', 'role', 'serial', 'type',
|
'id', 'name', 'facility_id', 'display_name', 'site', 'group', 'tenant', 'status', 'role', 'serial',
|
||||||
'width', 'u_height', 'desc_units', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
'asset_tag', 'type', 'width', 'u_height', 'desc_units', 'comments', 'tags', 'custom_fields', 'created',
|
||||||
|
'last_updated',
|
||||||
]
|
]
|
||||||
# Omit the UniqueTogetherValidator that would be automatically added to validate (group, facility_id). This
|
# Omit the UniqueTogetherValidator that would be automatically added to validate (group, facility_id). This
|
||||||
# prevents facility_id from being interpreted as a required field.
|
# prevents facility_id from being interpreted as a required field.
|
||||||
|
@ -194,13 +194,14 @@ class RackFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
to_field_name='slug',
|
to_field_name='slug',
|
||||||
label='Role (slug)',
|
label='Role (slug)',
|
||||||
)
|
)
|
||||||
|
asset_tag = NullableCharFieldFilter()
|
||||||
tag = django_filters.CharFilter(
|
tag = django_filters.CharFilter(
|
||||||
name='tags__slug',
|
name='tags__slug',
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Rack
|
model = Rack
|
||||||
fields = ['name', 'serial', 'type', 'width', 'u_height', 'desc_units']
|
fields = ['name', 'serial', 'asset_tag', 'type', 'width', 'u_height', 'desc_units']
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
@ -209,6 +210,7 @@ class RackFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
Q(name__icontains=value) |
|
Q(name__icontains=value) |
|
||||||
Q(facility_id__icontains=value) |
|
Q(facility_id__icontains=value) |
|
||||||
Q(serial__icontains=value.strip()) |
|
Q(serial__icontains=value.strip()) |
|
||||||
|
Q(asset_tag__icontains=value.strip()) |
|
||||||
Q(comments__icontains=value)
|
Q(comments__icontains=value)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -306,8 +306,8 @@ class RackForm(BootstrapMixin, TenancyForm, CustomFieldForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Rack
|
model = Rack
|
||||||
fields = [
|
fields = [
|
||||||
'site', 'group', 'name', 'facility_id', 'tenant_group', 'tenant', 'status', 'role', 'serial', 'type',
|
'site', 'group', 'name', 'facility_id', 'tenant_group', 'tenant', 'status', 'role', 'serial', 'asset_tag',
|
||||||
'width', 'u_height', 'desc_units', 'comments', 'tags',
|
'type', 'width', 'u_height', 'desc_units', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'site': "The site at which the rack exists",
|
'site': "The site at which the rack exists",
|
||||||
@ -437,6 +437,10 @@ class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
|||||||
required=False,
|
required=False,
|
||||||
label='Serial Number'
|
label='Serial Number'
|
||||||
)
|
)
|
||||||
|
asset_tag = forms.CharField(
|
||||||
|
max_length=50,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
type = forms.ChoiceField(
|
type = forms.ChoiceField(
|
||||||
choices=add_blank_choice(RACK_TYPE_CHOICES),
|
choices=add_blank_choice(RACK_TYPE_CHOICES),
|
||||||
required=False
|
required=False
|
||||||
@ -459,7 +463,7 @@ class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
|||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
nullable_fields = ['group', 'tenant', 'role', 'serial', 'comments']
|
nullable_fields = ['group', 'tenant', 'role', 'serial', 'asset_tag', 'comments']
|
||||||
|
|
||||||
|
|
||||||
class RackFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class RackFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Generated by Django 2.0.9 on 2018-11-01 19:44
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
import utilities.fields
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
@ -15,4 +15,9 @@ class Migration(migrations.Migration):
|
|||||||
name='status',
|
name='status',
|
||||||
field=models.PositiveSmallIntegerField(default=3),
|
field=models.PositiveSmallIntegerField(default=3),
|
||||||
),
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='rack',
|
||||||
|
name='asset_tag',
|
||||||
|
field=utilities.fields.NullableCharField(blank=True, max_length=50, null=True, unique=True),
|
||||||
|
),
|
||||||
]
|
]
|
@ -480,6 +480,14 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
verbose_name='Serial number'
|
verbose_name='Serial number'
|
||||||
)
|
)
|
||||||
|
asset_tag = NullableCharField(
|
||||||
|
max_length=50,
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
unique=True,
|
||||||
|
verbose_name='Asset tag',
|
||||||
|
help_text='A unique tag used to identify this rack'
|
||||||
|
)
|
||||||
type = models.PositiveSmallIntegerField(
|
type = models.PositiveSmallIntegerField(
|
||||||
choices=RACK_TYPE_CHOICES,
|
choices=RACK_TYPE_CHOICES,
|
||||||
blank=True,
|
blank=True,
|
||||||
@ -518,8 +526,8 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
tags = TaggableManager()
|
tags = TaggableManager()
|
||||||
|
|
||||||
csv_headers = [
|
csv_headers = [
|
||||||
'site', 'group_name', 'name', 'facility_id', 'tenant', 'status', 'role', 'type', 'serial', 'width', 'u_height',
|
'site', 'group_name', 'name', 'facility_id', 'tenant', 'status', 'role', 'type', 'serial', 'asset_tag', 'width',
|
||||||
'desc_units', 'comments',
|
'u_height', 'desc_units', 'comments',
|
||||||
]
|
]
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -579,6 +587,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
self.role.name if self.role else None,
|
self.role.name if self.role else None,
|
||||||
self.get_type_display() if self.type else None,
|
self.get_type_display() if self.type else None,
|
||||||
self.serial,
|
self.serial,
|
||||||
|
self.asset_tag,
|
||||||
self.width,
|
self.width,
|
||||||
self.u_height,
|
self.u_height,
|
||||||
self.desc_units,
|
self.desc_units,
|
||||||
|
@ -131,6 +131,16 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Asset Tag</td>
|
||||||
|
<td>
|
||||||
|
{% if rack.asset_tag %}
|
||||||
|
<span>{{ rack.asset_tag }}</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">N/A</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Devices</td>
|
<td>Devices</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
{% render_field form.status %}
|
{% render_field form.status %}
|
||||||
{% render_field form.role %}
|
{% render_field form.role %}
|
||||||
{% render_field form.serial %}
|
{% render_field form.serial %}
|
||||||
|
{% render_field form.asset_tag %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
Loading…
Reference in New Issue
Block a user