42 lines
2.0 KiB
Python
42 lines
2.0 KiB
Python
import os
|
|
import django
|
|
import re
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ups_management.settings')
|
|
django.setup()
|
|
|
|
from ups_manager.models import UPSHost, Battery
|
|
|
|
data = [
|
|
{'ups_model': '维谛/ITA40KVA', 'ups_quantity': 2, 'battery_brand': '松下蓄电池', 'location': '金融街C座18层', 'battery_model': '12V100AH', 'battery_weight': 25, 'battery_quantity': 32},
|
|
{'ups_model': '山特/CASTLE3C 10KVA', 'ups_quantity': 1, 'battery_brand': '松下蓄电池', 'location': '金融街C座18层', 'battery_model': '12V100AH', 'battery_weight': 25, 'battery_quantity': 16},
|
|
{'ups_model': '维谛/ITA40KVA', 'ups_quantity': 2, 'battery_brand': 'EXOP蓄电池', 'location': '金融街B座18层', 'battery_model': '12V100AH', 'battery_weight': 25, 'battery_quantity': 32},
|
|
{'ups_model': '维谛/ITA40KVA', 'ups_quantity': 3, 'battery_brand': 'EXOP蓄电池', 'location': '金融街B座17层', 'battery_model': '12V100AH', 'battery_weight': 25, 'battery_quantity': 64},
|
|
{'ups_model': '山特/CASTLE3C 10KVA', 'ups_quantity': 1, 'battery_brand': '松下蓄电池', 'location': '金融街B座7层', 'battery_model': '12V65AH', 'battery_weight': 25, 'battery_quantity': 32},
|
|
{'ups_model': '科华/YTR3340 40KVA', 'ups_quantity': 1, 'battery_brand': '理士蓄电池', 'location': '新盛大厦12/15层', 'battery_model': '12V100AH', 'battery_weight': 25, 'battery_quantity': 32},
|
|
]
|
|
|
|
for item in data:
|
|
ups_brand, ups_model = item['ups_model'].split('/', 1)
|
|
|
|
ups = UPSHost.objects.create(
|
|
brand=ups_brand.strip(),
|
|
model=ups_model.strip(),
|
|
ip_address='',
|
|
quantity=item['ups_quantity'],
|
|
location=item['location'],
|
|
)
|
|
|
|
Battery.objects.create(
|
|
brand=item['battery_brand'],
|
|
model=item['battery_model'],
|
|
weight=item['battery_weight'],
|
|
quantity=item['battery_quantity'],
|
|
location=item['location'],
|
|
ups_host=ups,
|
|
)
|
|
|
|
print(f"已导入: {ups.brand} {ups.model} - {item['battery_brand']} {item['battery_model']}")
|
|
|
|
print("\n数据导入完成!")
|