models.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:home-data-api 作者: data-skeptic 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号