In a django application I have the following model:
class Appointment(models.Model):
#some other fields
#address fields
zipcode=models.CharField(max_length=5)
address=models.CharField(max_length=120)
latitude=models.FloatField()
longitude=models.FloatField()
When I'm rendering an Appointment, I'm just putting a marker at the position specified by longitude and latitude with the address as text, however I need the latitude and longitude to do that.
Currently, latitude and longitude have to be entered manually in the admin backend, but opening Google Maps/OSM, searching for the address and entering latitude and longitude is work that shouldn't have to be done by hand, so I want to retrieve it through the Google Maps API (keyword Geocoding).
Ideally, I want a button "Get coordinates" next to the address, which, when pressed, starts a Geocoding request and fills in latitude and longitude when the address is unambiguous and presents a map with the results and fills in the coordinates when the user clicks on the right marker.
I know how to do that, but I'm not sure how I should insert the markup and the code into the admin backend.
Some things I already considered but don't want to do as they don't seem natural or seem to be too much work for such a simple task:
- putting the code in the address field's description in
field_options
in a class derived fromadmin.ModelAdmin
- putting everything address related in a separate model and using a custom
form
(with a separate template - create an address picker widget
- use GeoDjango