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
评论列表
文章目录