models.py 文件源码

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

项目:django-political-map 作者: 20tab 项目源码 文件源码
def _update_or_create_item(
            cls, geocode_result, types_list, url, parent, error_log=""):
        address_components = geocode_result['address_components'][0]
        location = geocode_result['geometry']['location']
        slug = slugify(address_components['short_name'])[:200]
        if slug == "":
            slug = slugify(address_components['long_name'])[:200]
        mapitem, _ = cls.objects.update_or_create(
            place_id=geocode_result['place_id'],
            defaults={
                'long_name': address_components['long_name'],
                'short_name': address_components['short_name'],
                'geo_type': _get_main_type(types_list),
                'types': ",".join(types_list),
                'response_json': json.dumps(geocode_result),
                'geocode': "{},{}".format(location['lat'], location['lng']),
                'slug': slug,
                'url': "{}/{}".format(url, slug),
                'parent': parent,
                'error_log': error_log,
            })
        return mapitem
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号