Fix UPS host form with custom form class for date handling

This commit is contained in:
xiaji
2026-04-30 14:46:57 +08:00
parent 7f0112d400
commit 749ab06ee7
3 changed files with 28 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ from django.views.generic import ListView, CreateView, UpdateView, DeleteView
from django.urls import reverse_lazy
from django.contrib import messages
from .models import UPSHost, Battery, Contact, Supplier, MaintenanceRecord
from .forms import BatteryFormSet
from .forms import BatteryFormSet, UPSHostForm
class DashboardView(ListView):
@@ -99,14 +99,14 @@ class UPSHostListView(ListView):
class UPSHostCreateView(CreateView):
model = UPSHost
template_name = 'ups_manager/ups_form.html'
fields = ['brand', 'model', 'ip_address', 'quantity', 'location', 'last_maintenance_date', 'contact']
form_class = UPSHostForm
success_url = reverse_lazy('ups_list')
class UPSHostUpdateView(UpdateView):
model = UPSHost
template_name = 'ups_manager/ups_form.html'
fields = ['brand', 'model', 'ip_address', 'quantity', 'location', 'last_maintenance_date', 'contact']
form_class = UPSHostForm
success_url = reverse_lazy('ups_list')
def get_context_data(self, **kwargs):