Getting ready

Register for a Google Maps API key and expose it to the templates, just like we did in the Using HTML5 data attributes recipe in Chapter 4, Templates and JavaScript. Note that for this recipe, in the Google Cloud Platform console, you will need to activate Maps JavaScript API and Geocoding API. For those APIs to function, you also need to set billing data.

We will continue by creating a locations app:

  1. Put the app under INSTALLED_APPS in the settings:
# myproject/settings/_base.pyINSTALLED_APPS = [    # …    "myproject.apps.locations",]
  1. Create a Location model there with a name, description, address, geographical coordinates, and picture, as follows:
# myproject/apps/locations/models.pyimport osimport uuidfrom collections import ...

Get Django 3 Web Development Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.