Package: django-ph-geography
Philippine Geography models for Djangodjango-ph-geographyprovides models for integrating regions, provinces, municipalities, and barangays in the Philippines.Data retrieved from the Philippine Standard Geographic Code (PSGC) published by Philippine Statistics Authority (PSA) on March 31, 2020 (https://psa.gov.ph/classification/psgc/downloads/PSGC%20Publication%20March2020.xlsx).Table of ContentsInstallationModelsMonkey PatchingInstallationInstalling usingpip:pip install django-ph-geographyAddph_geographytoINSTALLED_APPS:INSTALLED_APPS=[...'ph_geography',]Migrate app models to database:python manage.py migrate ph_geographyLoad initial data:python manage.py phgeofixturesModelsph_geography.models.RegionModel for regions. Available fields are:code(CharField<max_length=10, unique=True, null=False>): Unique geographical code for region.name(CharField<max_length=100, null=False)>): Geographical name for region.population(PositiveIntegerField<null=True>): Population count based on 2015 POPCEN. Null value means no data is available.island_group(CharField<max_length=1, choices=ISLAND_GROUP_CHOICES, null=False>): Island group where the region is located. Possible values are based on items in model propertyISLAND_GROUP_CHOICES:ISLAND_GROUP_LUZON('L') - LuzonISLAND_GROUP_VISAYAS('V') - VisayasISLAND_GROUP_MINDANAO('M') - Mindanaois_active(BooleanField<null=False, default=True>): Toggle if region is active (True) or not (False).ph_geography.models.ProvinceModel for provinces. Available fields are:code(CharField<max_length=10, unique=True, null=False>): Unique geographical code for region.name(CharField<max_length=100, null=False)>): Geographical name for region.population(PositiveIntegerField<null=True>): Population count based on 2015 POPCEN. Null value means no data is available.region(ForeignKey<Region,related_name='provinces',related_query_name='province',null=False, on_delete=models.CASCADE>): Region where province is located.income_class(CharField<max_length=1, choices=INCOME_CLASS_CHOICES, null=False, blank=True>): Income classification. Blank value means no data is available. Possible values are based on items in model propertyINCOME_CLASS_CHOICES:INCOME_CLASS_1('1') - 1stINCOME_CLASS_2('2') - 2ndINCOME_CLASS_3('3') - 3rdINCOME_CLASS_4('4') - 4thINCOME_CLASS_5('5') - 5thINCOME_CLASS_6('6') - 6thINCOME_CLASS_SPECIAL('S') - Specialis_active(BooleanField<null=False, default=True>): Toggle if province is active (True) or not (False).Available properties:island_group: Reference toRegionfieldisland_group.ph_geography.models.MunicipalityModel for municipalities and cities. Available fields are:code(CharField<max_length=10, unique=True, null=False>): Unique geographical code for region.name(CharField<max_length=100, null=False)>): Geographical name for region.population(PositiveIntegerField<null=True>): Population count based on 2015 POPCEN. Null value means no data is available.province(ForeignKey<Province,related_name='municipalities',related_query_name='municipality',null=False, on_delete=models.CASCADE>): Province where municipality is located.income_class(CharField<max_length=1, choices=INCOME_CLASS_CHOICES, null=False, blank=True>): Income classification. Blank value means no data is available. Possible values are based on items in model propertyINCOME_CLASS_CHOICES:INCOME_CLASS_1('1') - 1stINCOME_CLASS_2('2') - 2ndINCOME_CLASS_3('3') - 3rdINCOME_CLASS_4('4') - 4thINCOME_CLASS_5('5') - 5thINCOME_CLASS_6('6') - 6thINCOME_CLASS_SPECIAL('S') - Specialis_city(BooleanField<null=False>): Toggle to define whether the municipality is a city (True) or not (False).is_capital(BooleanField<null=False>): Toggle to define whether the municipality is a capital (True) or not (False).city_class(CharField<max_length=1, choices=CITY_CLASS_CHOICES, null=False, blank=True>): City legal classification. Blank value means no data is available. Possible values are based on items in model propertyCITY_CLASS_CHOICES:CITY_CLASS_COMPONENT_CITY('C') - CCCITY_CLASS_INDEPENDENT_COMPONENT_CITY('I') - ICCCITY_CLASS_HIGHLY_URBANIZED_CITY('H') - HUCis_active(BooleanField<null=False, default=True>): Toggle if municipality is active (True) or not (False).Available properties:island_group: Reference toRegionfieldisland_group.region: Reference toprovincefieldregion.ph_geography.models.BarangayModel for barangays. Available fields are:code(CharField<max_length=10, unique=True, null=False>): Unique geographical code for region.name(CharField<max_length=100, null=False)>): Geographical name for region.population(PositiveIntegerField<null=True>): Population count based on 2015 POPCEN. Null value means no data is available.municipality(ForeignKey<Municipality>,related_name='barangays',related_query_name='barangay',null=False, on_delete=models.CASCADE>): Municipality where barangay is located.is_urban(NullBooleanField<null=False>): Toggle to define whether the barangay is urban (True) or rural (False). Null value means no data is available.is_active(BooleanField<null=False, default=True>): Toggle if barangay is active (True) or not (False).Available properties:island_group: Reference toRegionfieldisland_group.province: Reference tomunicipalityfieldprovince.region: Reference to propertyprovincefieldregion.Monkey PatchingAfter migrating the models and loading the initial data through fixtures, you can monkey patch (if you’re into it)django-ph-geographymodels using the provided methods to suit your needs:Adding new fieldsYou can use the custom methodadd_fieldprovided by abstract model classph_geography.models.PhilippineGeographyto add fields to the models provided.
Using the said method to the abstract model will apply the action to all subclasses.Example:fromdjango.dbimportmodelsfromph_geography.modelsimportPhilippineGeographyfromph_geography.modelsimportRegion# Add field to Region, Province, Municipality, Barangay, and any subclass models of PhilippineGeographyPhilippineGeography.add_field('all_models',models.BooleanField(null=True))# Add field 'single_model' to RegionRegion.add_field('single_model',models.BooleanField(null=True))Removing existing fieldsYou can use the custom methodremove_fieldprovided by abstract model classph_geography.models.PhilippineGeographyto remove fields to the models provided.
Using the same method to the abstract model will apply the action to all subclasses.Example:fromph_geography.modelsimportPhilippineGeographyfromph_geography.modelsimportMunicipalityfromph_geography.modelsimportRegion# Remove field to Region, Province, Municipality, Barangay, and any subclass models of PhilippineGeographyPhilippineGeography.remove_field('population')# Remove field 'island_group' from RegionRegion.remove_field('island_group')# Multiple fields to remove are supportedMunicipality.remove_field('is_city','is_capital')