def result_to_country(result):
 if ('country' in result):
  mapbox_country = result['country']
  codes = dict(((v, k) for (k, v) in product_details.get_regions('en-US').iteritems()))
  code = codes.get(mapbox_country['name'], '')
  lookup_args = {'name': mapbox_country['name']}
  args = {'mapbox_id': mapbox_country['id'], 'code': code}
  args.update(lookup_args)
  query = (Q(**lookup_args) | Q(mapbox_id=mapbox_country['id']))
  country_qs = Country.objects.filter(query).distinct()
  if country_qs.exists():
   if (country_qs.count() == 2):
    deduplicate_countries(country_qs[0], country_qs[1])
   country_qs.update(**args)
   country = country_qs[0]
  else:
   country = Country.objects.create(**args)
  return country

def result_to_country ( result ) : if ( 'country' in result ) : mapbox_country = result [ 'country' ] codes = dict ( ( ( v , k ) for ( k , v ) in product_details . get_regions ( 'en-US' ) . iteritems ( ) ) ) code = codes . get ( mapbox_country [ 'name' ] , '' ) lookup_args = { 'name' : mapbox_country [ 'name' ] } args = { 'mapbox_id' : mapbox_country [ 'id' ] , 'code' : code } args . update ( lookup_args ) query = ( Q ( ** lookup_args ) | Q ( mapbox_id = mapbox_country [ 'id' ] ) ) country_qs = Country . objects . filter ( query ) . distinct ( ) if country_qs . exists ( ) : if ( country_qs . count ( ) == 2 ) : deduplicate_countries ( country_qs [ 0 ] , country_qs [ 1 ] ) country_qs . update ( ** args ) country = country_qs [ 0 ] else : country = Country . objects . create ( ** args ) return country
given one result from mapbox .