This is a django demonstration project that shows how django-address
can be used to geocode manually entered postal
addresses.
The person app is a simple implementation of a model called Person that includes an AddressField
and a
first_name. When you geocode an address using the main landing page of this app, it saves the name in an object with a
blank first_name.
You can use Django Admin to view the saved Person objects and add a first name if you like.
Note that the Person model uses Address field with null=True
.
By default, django-address
uses Cascade delete on AddressField.
This means if you for some reason delete an Address that is related to a Person or some other model, it will also delete the Person.
By setting null=True
, deleting the Address associated with a Person will keep the Person
object instance and set address
to null.
If not already installed, please install Docker.
Before building the example site, you will need to export three items into your environment:
export USER_ID=`id -u`
export GROUP_ID=`id -g`
export GOOGLE_API_KEY=<your-api-key>
The first two are used by Docker to ensure any files created are owned by your current user. The last is required to make your Google Maps API key available to the example site. Instructions for setting up an API key here: Google Maps API Key. Please note that this requires the set up of a billing account with Google.
This is hidden under Google Cloud Platform's console menu, under Other Google Solutions > Google Maps > APIs. (screenshot)
- Google Maps Javascript API
- Google Maps Places API
To run the example site, simply run:
docker-compose up
This will take care of launching a database, the server, and migrating the database.
docker-compose run --rm server python manage.py createsuperuser
The page shows a simple form entry field.
Check the browser console on the page for javascript errors. (Screenshot of an error)
ApiTargetBlockedMapError
: Your API key needs authorization to use the above services.ApiNotActivatedMapError
: Your API key needs Google Maps services to use the above services.
*NOTE: There is up to a several minute delay in making changes to project and api key settings. New keys can also take several minutes to be recognized.