def save(self, *args, **kwargs):
"""Save the model after geocoding the supplied address.
Here the address is geocoded using the Google geocoding service.
This is limited to 2500 requests per day. There is no current system
to account for this so models over 2500 will not geocode.
"""
if not settings.TESTING:
response = requests.get(
'https://maps.googleapis.com/maps/api/geocode/json',
params={'address': self.raw_address,
'key': settings.G_APPS_KEY})
if response.status_code == 200:
address = Address()
address.raw = response.text
address.from_google_json(response.json())
address.save()
self.address_object = address
super(Property, self).save(*args, **kwargs)
评论列表
文章目录