seed_shandong_cities.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from django.core.management.base import BaseCommand
  2. from ai_planner.models import City
  3. class Command(BaseCommand):
  4. help = 'Seeds the database with Shandong province city data'
  5. def handle(self, *args, **options):
  6. shandong_cities = [
  7. {
  8. "name": "济南市",
  9. "code": "jn",
  10. "description": "山东省省会,泉城",
  11. "is_hot": True
  12. },
  13. {
  14. "name": "青岛市",
  15. "code": "qd",
  16. "description": "计划单列市,海滨城市",
  17. "is_hot": True
  18. },
  19. {
  20. "name": "淄博市",
  21. "code": "zb",
  22. "description": "齐国故都,工业名城",
  23. "is_hot": False
  24. },
  25. {
  26. "name": "枣庄市",
  27. "code": "zz",
  28. "description": "铁道游击队故乡",
  29. "is_hot": False
  30. },
  31. {
  32. "name": "东营市",
  33. "code": "dy",
  34. "description": "黄河入海口,石油之城",
  35. "is_hot": False
  36. },
  37. {
  38. "name": "烟台市",
  39. "code": "yt",
  40. "description": "葡萄酒城,海滨城市",
  41. "is_hot": True
  42. },
  43. {
  44. "name": "潍坊市",
  45. "code": "wf",
  46. "description": "世界风筝之都",
  47. "is_hot": False
  48. },
  49. {
  50. "name": "济宁市",
  51. "code": "jn2",
  52. "description": "孔孟之乡,运河之都",
  53. "is_hot": False
  54. },
  55. {
  56. "name": "泰安市",
  57. "code": "ta",
  58. "description": "泰山所在地",
  59. "is_hot": True
  60. },
  61. {
  62. "name": "威海市",
  63. "code": "wh",
  64. "description": "最适合人类居住城市",
  65. "is_hot": True
  66. },
  67. {
  68. "name": "日照市",
  69. "code": "rz",
  70. "description": "东方太阳城",
  71. "is_hot": False
  72. },
  73. {
  74. "name": "临沂市",
  75. "code": "ly",
  76. "description": "商贸物流之都",
  77. "is_hot": False
  78. },
  79. {
  80. "name": "德州市",
  81. "code": "dz",
  82. "description": "中国太阳城",
  83. "is_hot": False
  84. },
  85. {
  86. "name": "聊城市",
  87. "code": "lc",
  88. "description": "江北水城",
  89. "is_hot": False
  90. },
  91. {
  92. "name": "滨州市",
  93. "code": "bz",
  94. "description": "黄河三角洲中心",
  95. "is_hot": False
  96. },
  97. {
  98. "name": "菏泽市",
  99. "code": "hz",
  100. "description": "中国牡丹之都",
  101. "is_hot": False
  102. }
  103. ]
  104. created_count = 0
  105. for city_data in shandong_cities:
  106. _, created = City.objects.get_or_create(
  107. code=city_data["code"],
  108. defaults=city_data
  109. )
  110. if created:
  111. created_count += 1
  112. self.stdout.write(
  113. self.style.SUCCESS(f'成功添加 {created_count} 个山东省城市数据(共 {len(shandong_cities)} 个)')
  114. )