Initial commit: UPS management system
This commit is contained in:
34
ups_management/update_data.py
Normal file
34
ups_management/update_data.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import django
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ups_management.settings')
|
||||
django.setup()
|
||||
|
||||
from ups_manager.models import UPSHost, Battery, Contact
|
||||
|
||||
print("=== 开始处理任务 ===")
|
||||
|
||||
print("\n1. 创建联系人 '夏骥'...")
|
||||
contact, created = Contact.objects.get_or_create(
|
||||
name='夏骥',
|
||||
defaults={
|
||||
'phone': '',
|
||||
'email': ''
|
||||
}
|
||||
)
|
||||
print(f" 联系人 {'已创建' if created else '已存在'}: {contact.name}")
|
||||
|
||||
print("\n2. 更新所有UPS主机的上次维保时间和联系人...")
|
||||
ups_count = UPSHost.objects.all().count()
|
||||
UPSHost.objects.update(
|
||||
last_maintenance_date='2026-03-06',
|
||||
contact=contact
|
||||
)
|
||||
print(f" 已更新 {ups_count} 台UPS主机")
|
||||
|
||||
print("\n3. 更新所有电池的上次维保时间...")
|
||||
battery_count = Battery.objects.all().count()
|
||||
Battery.objects.update(last_maintenance_date='2026-03-06')
|
||||
print(f" 已更新 {battery_count} 块电池")
|
||||
|
||||
print("\n=== 任务完成 ===")
|
||||
Reference in New Issue
Block a user