Running the layer mapping 

At the bottom of load.py, create a function called run that contains the following code. Note that the names of the mappings (for example, us_states_mapping) will have to match the names of the dictionaries:

def run(verbose=True):
lm = LayerMapping(
US_States, states_shp, us_states_mapping,
transform=False, encoding='iso-8859-1',
)
lm.save(strict=True, verbose=verbose)
lm = LayerMapping(
Counties, counties_shp, us_counties_mapping,
transform=False, encoding='iso-8859-1',
)
lm.save(strict=True, verbose=verbose)
lm = LayerMapping(
Districts, districts_shp, districts_mapping,
transform=False, encoding='iso-8859-1',
)
lm.save(strict=True, verbose=verbose)
lm = LayerMapping(
Arenas, arenas_shp, arenas_mapping,
transform=False, encoding='iso-8859-1',
)
lm.save(strict=True, verbose=verbose)

To run the script, we will use the manage.py shell argument to invoke a Python shell, and then import the load.py file and execute the run function inside this local shell: 

>>> from arenas import load
>>> load.run()

Once the run function is called and executed, the rows of data in the shapefiles are imported into the database tables:

Once the function completes successfully, the database tables will be populated. We can now explore a very useful feature of Django—the built-in admin panel.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset