def result_to_city(result, country, region):
 if ('city' in result):
  mapbox_city = result['city']
  lookup_args = {'name': mapbox_city['name'], 'country': country, 'region': region}
  args = {'mapbox_id': mapbox_city['id'], 'lat': mapbox_city['lat'], 'lng': mapbox_city['lon']}
  args.update(lookup_args)
  query = (Q(**lookup_args) | Q(mapbox_id=mapbox_city['id']))
  city_qs = City.objects.filter(query).distinct()
  if city_qs.exists():
   if (city_qs.count() == 2):
    deduplicate_cities(city_qs[0], city_qs[1])
   city_qs.update(**args)
   city = city_qs[0]
  else:
   city = City.objects.create(**args)
  return city

def result_to_city ( result , country , region ) : if ( 'city' in result ) : mapbox_city = result [ 'city' ] lookup_args = { 'name' : mapbox_city [ 'name' ] , 'country' : country , 'region' : region } args = { 'mapbox_id' : mapbox_city [ 'id' ] , 'lat' : mapbox_city [ 'lat' ] , 'lng' : mapbox_city [ 'lon' ] } args . update ( lookup_args ) query = ( Q ( ** lookup_args ) | Q ( mapbox_id = mapbox_city [ 'id' ] ) ) city_qs = City . objects . filter ( query ) . distinct ( ) if city_qs . exists ( ) : if ( city_qs . count ( ) == 2 ) : deduplicate_cities ( city_qs [ 0 ] , city_qs [ 1 ] ) city_qs . update ( ** args ) city = city_qs [ 0 ] else : city = City . objects . create ( ** args ) return city
given one result from mapbox .