diff --git a/ups_management/ups_manager/forms.py b/ups_management/ups_manager/forms.py new file mode 100644 index 0000000..82a8076 --- /dev/null +++ b/ups_management/ups_manager/forms.py @@ -0,0 +1,35 @@ +from django import forms +from django.forms import inlineformset_factory +from .models import UPSHost, Battery + + +class BatteryForm(forms.ModelForm): + class Meta: + model = Battery + fields = ['brand', 'model', 'weight', 'quantity', 'location', 'install_date', 'last_maintenance_date'] + labels = { + 'brand': '电池品牌', + 'model': '电池型号', + 'weight': '重量(kg)', + 'quantity': '数量', + 'location': '存放位置', + 'install_date': '安装日期', + 'last_maintenance_date': '上次维保时间', + } + widgets = { + 'brand': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), + 'model': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), + 'weight': forms.NumberInput(attrs={'class': 'form-control form-control-sm', 'step': '0.1'}), + 'quantity': forms.NumberInput(attrs={'class': 'form-control form-control-sm', 'min': '1'}), + 'location': forms.TextInput(attrs={'class': 'form-control form-control-sm'}), + } + + +BatteryFormSet = inlineformset_factory( + UPSHost, + Battery, + form=BatteryForm, + extra=0, + can_delete=True, + fields=['brand', 'model', 'weight', 'quantity', 'location', 'install_date', 'last_maintenance_date'] +) diff --git a/ups_management/ups_manager/templates/ups_manager/ups_form.html b/ups_management/ups_manager/templates/ups_manager/ups_form.html index 293d479..a81bb8f 100644 --- a/ups_management/ups_manager/templates/ups_manager/ups_form.html +++ b/ups_management/ups_manager/templates/ups_manager/ups_form.html @@ -116,6 +116,114 @@ + {% if object and battery_formset %} +
| 电池品牌 | +电池型号 | +重量(kg) | +数量 | +存放位置 | +安装日期 | +上次维保 | +删除 | +
|---|---|---|---|---|---|---|---|
|
+ {{ battery_form.id }}
+ {{ battery_form.brand }}
+ {% if battery_form.brand.errors %}
+ {% for error in battery_form.brand.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+
+ {{ battery_form.model }}
+ {% if battery_form.model.errors %}
+ {% for error in battery_form.model.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+
+ {{ battery_form.weight }}
+ {% if battery_form.weight.errors %}
+ {% for error in battery_form.weight.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+
+ {{ battery_form.quantity }}
+ {% if battery_form.quantity.errors %}
+ {% for error in battery_form.quantity.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+
+ {{ battery_form.location }}
+ {% if battery_form.location.errors %}
+ {% for error in battery_form.location.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+
+
+ {% if battery_form.install_date.errors %}
+ {% for error in battery_form.install_date.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+
+
+ {% if battery_form.last_maintenance_date.errors %}
+ {% for error in battery_form.last_maintenance_date.errors %}
+ {{ error }}
+ {% endfor %}
+ {% endif %}
+ |
+ + {{ battery_form.DELETE }} + | +
| 暂未下挂电池 | +|||||||