seed_shandong_cities.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. "latitude": 36.6512,
  12. "longitude": 117.1201,
  13. "is_hot": True
  14. },
  15. {
  16. "name": "青岛市",
  17. "code": "qd",
  18. "description": "计划单列市,海滨城市",
  19. "latitude": 36.0671,
  20. "longitude": 120.3826,
  21. "is_hot": True
  22. },
  23. {
  24. "name": "淄博市",
  25. "code": "zb",
  26. "description": "齐国故都,工业名城",
  27. "latitude": 36.8135,
  28. "longitude": 118.0549,
  29. "is_hot": False
  30. },
  31. {
  32. "name": "枣庄市",
  33. "code": "zz",
  34. "description": "铁道游击队故乡",
  35. "latitude": 34.8105,
  36. "longitude": 117.3238,
  37. "is_hot": False
  38. },
  39. {
  40. "name": "东营市",
  41. "code": "dy",
  42. "description": "黄河入海口,石油之城",
  43. "latitude": 37.4335,
  44. "longitude": 118.6746,
  45. "is_hot": False
  46. },
  47. {
  48. "name": "烟台市",
  49. "code": "yt",
  50. "description": "葡萄酒城,海滨城市",
  51. "latitude": 37.4638,
  52. "longitude": 121.4479,
  53. "is_hot": True
  54. },
  55. {
  56. "name": "潍坊市",
  57. "code": "wf",
  58. "description": "世界风筝之都",
  59. "latitude": 36.7069,
  60. "longitude": 119.1617,
  61. "is_hot": False
  62. },
  63. {
  64. "name": "济宁市",
  65. "code": "jn2",
  66. "description": "孔孟之乡,运河之都",
  67. "latitude": 35.4149,
  68. "longitude": 116.5872,
  69. "is_hot": False
  70. },
  71. {
  72. "name": "泰安市",
  73. "code": "ta",
  74. "description": "泰山所在地",
  75. "latitude": 36.2001,
  76. "longitude": 117.0887,
  77. "is_hot": True
  78. },
  79. {
  80. "name": "威海市",
  81. "code": "wh",
  82. "description": "最适合人类居住城市",
  83. "latitude": 37.5131,
  84. "longitude": 122.1217,
  85. "is_hot": True
  86. },
  87. {
  88. "name": "日照市",
  89. "code": "rz",
  90. "description": "东方太阳城",
  91. "latitude": 35.4167,
  92. "longitude": 119.5266,
  93. "is_hot": False
  94. },
  95. {
  96. "name": "临沂市",
  97. "code": "ly",
  98. "description": "商贸物流之都",
  99. "latitude": 35.1047,
  100. "longitude": 118.3565,
  101. "is_hot": False
  102. },
  103. {
  104. "name": "德州市",
  105. "code": "dz",
  106. "description": "中国太阳城",
  107. "latitude": 37.4341,
  108. "longitude": 116.3575,
  109. "is_hot": False
  110. },
  111. {
  112. "name": "聊城市",
  113. "code": "lc",
  114. "description": "江北水城",
  115. "latitude": 36.4567,
  116. "longitude": 115.9854,
  117. "is_hot": False
  118. },
  119. {
  120. "name": "滨州市",
  121. "code": "bz",
  122. "description": "黄河三角洲中心",
  123. "latitude": 37.3819,
  124. "longitude": 118.0167,
  125. "is_hot": False
  126. },
  127. {
  128. "name": "菏泽市",
  129. "code": "hz",
  130. "description": "中国牡丹之都",
  131. "latitude": 35.2336,
  132. "longitude": 115.4807,
  133. "is_hot": False
  134. }
  135. ]
  136. created_count = 0
  137. for city_data in shandong_cities:
  138. _, created = City.objects.get_or_create(
  139. code=city_data["code"],
  140. defaults=city_data
  141. )
  142. if created:
  143. created_count += 1
  144. self.stdout.write(
  145. self.style.SUCCESS(f'成功添加 {created_count} 个山东省城市数据(共 {len(shandong_cities)} 个)')
  146. )