def result_to_region(result, country):
 if ('province' in result):
  mapbox_region = result['province']
  lookup_args = {'name': mapbox_region['name'], 'country': country}
  args = {'mapbox_id': mapbox_region['id']}
  args.update(lookup_args)
  query = (Q(**lookup_args) | Q(mapbox_id=mapbox_region['id']))
  region_qs = Region.objects.filter(query).distinct()
  if region_qs.exists():
   if (region_qs.count() == 2):
    deduplicate_regions(region_qs[0], region_qs[1])
   region_qs.update(**args)
   region = region_qs[0]
  else:
   region = Region.objects.create(**args)
  return region

def result_to_region ( result , country ) : if ( 'province' in result ) : mapbox_region = result [ 'province' ] lookup_args = { 'name' : mapbox_region [ 'name' ] , 'country' : country } args = { 'mapbox_id' : mapbox_region [ 'id' ] } args . update ( lookup_args ) query = ( Q ( ** lookup_args ) | Q ( mapbox_id = mapbox_region [ 'id' ] ) ) region_qs = Region . objects . filter ( query ) . distinct ( ) if region_qs . exists ( ) : if ( region_qs . count ( ) == 2 ) : deduplicate_regions ( region_qs [ 0 ] , region_qs [ 1 ] ) region_qs . update ( ** args ) region = region_qs [ 0 ] else : region = Region . objects . create ( ** args ) return region
given one result from mapbox and a country object .