123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 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": "山东省省会,泉城",
- "latitude": 36.6512,
- "longitude": 117.1201,
- "is_hot": True
- },
- {
- "name": "青岛市",
- "code": "qd",
- "description": "计划单列市,海滨城市",
- "latitude": 36.0671,
- "longitude": 120.3826,
- "is_hot": True
- },
- {
- "name": "淄博市",
- "code": "zb",
- "description": "齐国故都,工业名城",
- "latitude": 36.8135,
- "longitude": 118.0549,
- "is_hot": False
- },
- {
- "name": "枣庄市",
- "code": "zz",
- "description": "铁道游击队故乡",
- "latitude": 34.8105,
- "longitude": 117.3238,
- "is_hot": False
- },
- {
- "name": "东营市",
- "code": "dy",
- "description": "黄河入海口,石油之城",
- "latitude": 37.4335,
- "longitude": 118.6746,
- "is_hot": False
- },
- {
- "name": "烟台市",
- "code": "yt",
- "description": "葡萄酒城,海滨城市",
- "latitude": 37.4638,
- "longitude": 121.4479,
- "is_hot": True
- },
- {
- "name": "潍坊市",
- "code": "wf",
- "description": "世界风筝之都",
- "latitude": 36.7069,
- "longitude": 119.1617,
- "is_hot": False
- },
- {
- "name": "济宁市",
- "code": "jn2",
- "description": "孔孟之乡,运河之都",
- "latitude": 35.4149,
- "longitude": 116.5872,
- "is_hot": False
- },
- {
- "name": "泰安市",
- "code": "ta",
- "description": "泰山所在地",
- "latitude": 36.2001,
- "longitude": 117.0887,
- "is_hot": True
- },
- {
- "name": "威海市",
- "code": "wh",
- "description": "最适合人类居住城市",
- "latitude": 37.5131,
- "longitude": 122.1217,
- "is_hot": True
- },
- {
- "name": "日照市",
- "code": "rz",
- "description": "东方太阳城",
- "latitude": 35.4167,
- "longitude": 119.5266,
- "is_hot": False
- },
- {
- "name": "临沂市",
- "code": "ly",
- "description": "商贸物流之都",
- "latitude": 35.1047,
- "longitude": 118.3565,
- "is_hot": False
- },
- {
- "name": "德州市",
- "code": "dz",
- "description": "中国太阳城",
- "latitude": 37.4341,
- "longitude": 116.3575,
- "is_hot": False
- },
- {
- "name": "聊城市",
- "code": "lc",
- "description": "江北水城",
- "latitude": 36.4567,
- "longitude": 115.9854,
- "is_hot": False
- },
- {
- "name": "滨州市",
- "code": "bz",
- "description": "黄河三角洲中心",
- "latitude": 37.3819,
- "longitude": 118.0167,
- "is_hot": False
- },
- {
- "name": "菏泽市",
- "code": "hz",
- "description": "中国牡丹之都",
- "latitude": 35.2336,
- "longitude": 115.4807,
- "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)} 个)')
- )
|