|
1 | 1 | """ |
2 | 2 | Django management command to populate Asia Pacific geography data. |
3 | | -Covers: India, Indonesia, Thailand at state/province level. |
| 3 | +Covers: India, Indonesia, Thailand, Philippines at state/province level. |
4 | 4 |
|
5 | 5 | Usage: |
6 | 6 | python manage.py populate_geographies |
|
17 | 17 |
|
18 | 18 |
|
19 | 19 | class Command(BaseCommand): |
20 | | - help = "Populate Asia Pacific geography data (India, Indonesia, Thailand)" |
| 20 | + help = ( |
| 21 | + "Populate Asia Pacific geography data (India, Indonesia, Thailand, Philippines)" |
| 22 | + ) |
21 | 23 |
|
22 | 24 | def add_arguments(self, parser: CommandParser) -> None: |
23 | 25 | parser.add_argument( |
@@ -64,6 +66,9 @@ def _populate_geographies(self) -> None: |
64 | 66 | # Thailand and its provinces |
65 | 67 | self._populate_thailand(asia_pacific) |
66 | 68 |
|
| 69 | + # Philippines and its provinces |
| 70 | + self._populate_philippines(asia_pacific) |
| 71 | + |
67 | 72 | def _populate_india(self, parent: Geography) -> None: |
68 | 73 | """Populate India and its states/UTs.""" |
69 | 74 | india, created = Geography.objects.get_or_create( |
@@ -302,3 +307,133 @@ def _populate_thailand(self, parent: Geography) -> None: |
302 | 307 | self.stdout.write( |
303 | 308 | f"Thai provinces: {created_count} created, {len(thai_provinces) - created_count} already existed" |
304 | 309 | ) |
| 310 | + |
| 311 | + def _populate_philippines(self, parent: Geography) -> None: |
| 312 | + """Populate Philippines and its provinces.""" |
| 313 | + philippines, created = Geography.objects.get_or_create( |
| 314 | + name="Philippines", |
| 315 | + defaults={"code": "PH", "type": GeoTypes.COUNTRY, "parent_id": parent}, |
| 316 | + ) |
| 317 | + if created: |
| 318 | + self.stdout.write(f"Created country: {philippines.name}") |
| 319 | + else: |
| 320 | + self.stdout.write(f"Country already exists: {philippines.name}") |
| 321 | + |
| 322 | + philippine_provinces = [ |
| 323 | + # Luzon - NCR |
| 324 | + ("Metro Manila", "NCR"), |
| 325 | + # Luzon - CAR |
| 326 | + ("Abra", "ABR"), |
| 327 | + ("Apayao", "APA"), |
| 328 | + ("Benguet", "BEN"), |
| 329 | + ("Ifugao", "IFU"), |
| 330 | + ("Kalinga", "KAL"), |
| 331 | + ("Mountain Province", "MOU"), |
| 332 | + # Luzon - Region I (Ilocos) |
| 333 | + ("Ilocos Norte", "ILN"), |
| 334 | + ("Ilocos Sur", "ILS"), |
| 335 | + ("La Union", "LUN"), |
| 336 | + ("Pangasinan", "PAN"), |
| 337 | + # Luzon - Region II (Cagayan Valley) |
| 338 | + ("Batanes", "BTN"), |
| 339 | + ("Cagayan", "CAG"), |
| 340 | + ("Isabela", "ISA"), |
| 341 | + ("Nueva Vizcaya", "NUV"), |
| 342 | + ("Quirino", "QUI"), |
| 343 | + # Luzon - Region III (Central Luzon) |
| 344 | + ("Aurora", "AUR"), |
| 345 | + ("Bataan", "BAN"), |
| 346 | + ("Bulacan", "BUL"), |
| 347 | + ("Nueva Ecija", "NUE"), |
| 348 | + ("Pampanga", "PAM"), |
| 349 | + ("Tarlac", "TAR"), |
| 350 | + ("Zambales", "ZMB"), |
| 351 | + # Luzon - Region IV-A (CALABARZON) |
| 352 | + ("Batangas", "BTG"), |
| 353 | + ("Cavite", "CAV"), |
| 354 | + ("Laguna", "LAG"), |
| 355 | + ("Quezon", "QUE"), |
| 356 | + ("Rizal", "RIZ"), |
| 357 | + # Luzon - Region IV-B (MIMAROPA) |
| 358 | + ("Marinduque", "MAD"), |
| 359 | + ("Occidental Mindoro", "MDC"), |
| 360 | + ("Oriental Mindoro", "MDR"), |
| 361 | + ("Palawan", "PLW"), |
| 362 | + ("Romblon", "ROM"), |
| 363 | + # Luzon - Region V (Bicol) |
| 364 | + ("Albay", "ALB"), |
| 365 | + ("Camarines Norte", "CAN"), |
| 366 | + ("Camarines Sur", "CAS"), |
| 367 | + ("Catanduanes", "CAT"), |
| 368 | + ("Masbate", "MAS"), |
| 369 | + ("Sorsogon", "SOR"), |
| 370 | + # Visayas - Region VI (Western Visayas) |
| 371 | + ("Aklan", "AKL"), |
| 372 | + ("Antique", "ANT"), |
| 373 | + ("Capiz", "CAP"), |
| 374 | + ("Guimaras", "GUI"), |
| 375 | + ("Iloilo", "ILI"), |
| 376 | + ("Negros Occidental", "NEC"), |
| 377 | + # Visayas - Region VII (Central Visayas) |
| 378 | + ("Bohol", "BOH"), |
| 379 | + ("Cebu", "CEB"), |
| 380 | + ("Negros Oriental", "NER"), |
| 381 | + ("Siquijor", "SIG"), |
| 382 | + # Visayas - Region VIII (Eastern Visayas) |
| 383 | + ("Biliran", "BIL"), |
| 384 | + ("Eastern Samar", "EAS"), |
| 385 | + ("Leyte", "LEY"), |
| 386 | + ("Northern Samar", "NSA"), |
| 387 | + ("Samar", "WSA"), |
| 388 | + ("Southern Leyte", "SLE"), |
| 389 | + # Mindanao - Region IX (Zamboanga Peninsula) |
| 390 | + ("Zamboanga del Norte", "ZAN"), |
| 391 | + ("Zamboanga del Sur", "ZAS"), |
| 392 | + ("Zamboanga Sibugay", "ZSI"), |
| 393 | + # Mindanao - Region X (Northern Mindanao) |
| 394 | + ("Bukidnon", "BUK"), |
| 395 | + ("Camiguin", "CAM"), |
| 396 | + ("Lanao del Norte", "LAN"), |
| 397 | + ("Misamis Occidental", "MSC"), |
| 398 | + ("Misamis Oriental", "MSR"), |
| 399 | + # Mindanao - Region XI (Davao) |
| 400 | + ("Davao de Oro", "COM"), |
| 401 | + ("Davao del Norte", "DAV"), |
| 402 | + ("Davao del Sur", "DAS"), |
| 403 | + ("Davao Occidental", "DAO"), |
| 404 | + ("Davao Oriental", "DAO"), |
| 405 | + # Mindanao - Region XII (SOCCSKSARGEN) |
| 406 | + ("Cotabato", "NCO"), |
| 407 | + ("Sarangani", "SAR"), |
| 408 | + ("South Cotabato", "SCO"), |
| 409 | + ("Sultan Kudarat", "SUK"), |
| 410 | + # Mindanao - Region XIII (Caraga) |
| 411 | + ("Agusan del Norte", "AGN"), |
| 412 | + ("Agusan del Sur", "AGS"), |
| 413 | + ("Dinagat Islands", "DIN"), |
| 414 | + ("Surigao del Norte", "SUN"), |
| 415 | + ("Surigao del Sur", "SUR"), |
| 416 | + # Mindanao - BARMM |
| 417 | + ("Basilan", "BAS"), |
| 418 | + ("Lanao del Sur", "LAS"), |
| 419 | + ("Maguindanao", "MAG"), |
| 420 | + ("Sulu", "SLU"), |
| 421 | + ("Tawi-Tawi", "TAW"), |
| 422 | + ] |
| 423 | + |
| 424 | + created_count = 0 |
| 425 | + for province_name, province_code in philippine_provinces: |
| 426 | + _, created = Geography.objects.get_or_create( |
| 427 | + name=province_name, |
| 428 | + defaults={ |
| 429 | + "code": province_code, |
| 430 | + "type": GeoTypes.STATE, |
| 431 | + "parent_id": philippines, |
| 432 | + }, |
| 433 | + ) |
| 434 | + if created: |
| 435 | + created_count += 1 |
| 436 | + |
| 437 | + self.stdout.write( |
| 438 | + f"Philippine provinces: {created_count} created, {len(philippine_provinces) - created_count} already existed" |
| 439 | + ) |
0 commit comments