123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- from django.core.management.base import BaseCommand
- from ai_planner.models import City
- class Command(BaseCommand):
- help = 'Seeds the database with Shandong province city data'
- def handle(self, *args, **options):
- shandong_cities = [
- {
- "name": "济南市",
- "code": "jn",
- "description": "山东省省会,泉城",
- "is_hot": True
- },
- {
- "name": "青岛市",
- "code": "qd",
- "description": "计划单列市,海滨城市",
- "is_hot": True
- },
- {
- "name": "淄博市",
- "code": "zb",
- "description": "齐国故都,工业名城",
- "is_hot": False
- },
- {
- "name": "枣庄市",
- "code": "zz",
- "description": "铁道游击队故乡",
- "is_hot": False
- },
- {
- "name": "东营市",
- "code": "dy",
- "description": "黄河入海口,石油之城",
- "is_hot": False
- },
- {
- "name": "烟台市",
- "code": "yt",
- "description": "葡萄酒城,海滨城市",
- "is_hot": True
- },
- {
- "name": "潍坊市",
- "code": "wf",
- "description": "世界风筝之都",
- "is_hot": False
- },
- {
- "name": "济宁市",
- "code": "jn2",
- "description": "孔孟之乡,运河之都",
- "is_hot": False
- },
- {
- "name": "泰安市",
- "code": "ta",
- "description": "泰山所在地",
- "is_hot": True
- },
- {
- "name": "威海市",
- "code": "wh",
- "description": "最适合人类居住城市",
- "is_hot": True
- },
- {
- "name": "日照市",
- "code": "rz",
- "description": "东方太阳城",
- "is_hot": False
- },
- {
- "name": "临沂市",
- "code": "ly",
- "description": "商贸物流之都",
- "is_hot": False
- },
- {
- "name": "德州市",
- "code": "dz",
- "description": "中国太阳城",
- "is_hot": False
- },
- {
- "name": "聊城市",
- "code": "lc",
- "description": "江北水城",
- "is_hot": False
- },
- {
- "name": "滨州市",
- "code": "bz",
- "description": "黄河三角洲中心",
- "is_hot": False
- },
- {
- "name": "菏泽市",
- "code": "hz",
- "description": "中国牡丹之都",
- "is_hot": False
- }
- ]
- created_count = 0
- for city_data in shandong_cities:
- _, created = City.objects.get_or_create(
- code=city_data["code"],
- defaults=city_data
- )
- if created:
- created_count += 1
- self.stdout.write(
- self.style.SUCCESS(f'成功添加 {created_count} 个山东省城市数据(共 {len(shandong_cities)} 个)')
- )
|