Add battery inline editing for UPS host
This commit is contained in:
35
ups_management/ups_manager/forms.py
Normal file
35
ups_management/ups_manager/forms.py
Normal file
@@ -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']
|
||||
)
|
||||
Reference in New Issue
Block a user