Add serial number field to UPS host

This commit is contained in:
xiaji
2026-05-18 13:37:52 +08:00
parent dade358058
commit fbed049ef4
5 changed files with 39 additions and 2 deletions

View File

@@ -6,10 +6,11 @@ from .models import UPSHost, Battery
class UPSHostForm(forms.ModelForm):
class Meta:
model = UPSHost
fields = ['brand', 'model', 'ip_address', 'quantity', 'location', 'last_maintenance_date', 'contact']
fields = ['brand', 'model', 'serial_number', 'ip_address', 'quantity', 'location', 'last_maintenance_date', 'contact']
labels = {
'brand': '品牌',
'model': '型号',
'serial_number': '序列号',
'ip_address': 'IP地址',
'quantity': '数量',
'location': '存放位置',
@@ -19,6 +20,7 @@ class UPSHostForm(forms.ModelForm):
widgets = {
'brand': forms.TextInput(attrs={'class': 'form-control'}),
'model': forms.TextInput(attrs={'class': 'form-control'}),
'serial_number': forms.TextInput(attrs={'class': 'form-control'}),
'ip_address': forms.TextInput(attrs={'class': 'form-control'}),
'quantity': forms.NumberInput(attrs={'class': 'form-control', 'min': '1'}),
'location': forms.TextInput(attrs={'class': 'form-control'}),

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2026-05-18 05:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ups_manager', '0005_alter_upshost_ip_address'),
]
operations = [
migrations.AddField(
model_name='upshost',
name='serial_number',
field=models.CharField(blank=True, max_length=100, null=True, verbose_name='序列号'),
),
]

View File

@@ -36,6 +36,7 @@ class Supplier(models.Model):
class UPSHost(models.Model):
brand = models.CharField(max_length=100, verbose_name='品牌')
model = models.CharField(max_length=100, verbose_name='型号')
serial_number = models.CharField(max_length=100, blank=True, null=True, verbose_name='序列号')
ip_address = models.CharField(max_length=50, blank=True, null=True, verbose_name='IP地址')
quantity = models.IntegerField(default=1, verbose_name='数量')
location = models.CharField(max_length=200, verbose_name='存放位置')

View File

@@ -40,6 +40,20 @@
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="{{ form.serial_number.id_for_label }}" class="form-label font-weight-semibold">
{{ form.serial_number.label }}
</label>
{{ form.serial_number }}
{% if form.serial_number.errors %}
{% for error in form.serial_number.errors %}
<div class="invalid-feedback d-block">{{ error }}</div>
{% endfor %}
{% endif %}
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="{{ form.ip_address.id_for_label }}" class="form-label font-weight-semibold">

View File

@@ -33,6 +33,7 @@
<th>主机名称</th>
<th>品牌</th>
<th>型号</th>
<th>序列号</th>
<th>IP地址</th>
<th>数量</th>
<th>存放位置</th>
@@ -49,6 +50,7 @@
<td>{{ ups.brand }} {{ ups.model }}</td>
<td>{{ ups.brand }}</td>
<td>{{ ups.model }}</td>
<td>{{ ups.serial_number|default:"-" }}</td>
<td>{{ ups.ip_address }}</td>
<td>{{ ups.quantity }}</td>
<td>{{ ups.location }}</td>
@@ -62,7 +64,7 @@
</tr>
{% empty %}
<tr>
<td colspan="11" class="text-center text-muted">暂无UPS主机记录</td>
<td colspan="12" class="text-center text-muted">暂无UPS主机记录</td>
</tr>
{% endfor %}
</tbody>