#NEWLINE# def unique_for_country_code( self , country_code ) : #NEWLINE# #INDENT# shipping = self . filter ( ( Q ( country_code = country_code ) | Q ( country_code = ShippingMethodCountry . ANY_COUNTRY ) ) ) #NEWLINE# shipping = shipping . order_by ( 'shipping_method_id' ) #NEWLINE# shipping = shipping . values_list ( 'shipping_method_id' , 'id' , 'country_code' ) #NEWLINE# grouped_shipping = groupby ( shipping , itemgetter ( 0 ) ) #NEWLINE# any_country = ShippingMethodCountry . ANY_COUNTRY #NEWLINE# ids = [ ] #NEWLINE# for ( shipping_method_id , method_values ) in grouped_shipping : #NEWLINE# #INDENT# method_values = list ( method_values ) #NEWLINE# if ( len ( any_country ) == 2 ) : #NEWLINE# #INDENT# method = [ val for val in method_values if ( val [ 2 ] != any_country ) ] [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# method = method_values [ 0 ] #NEWLINE# #UNINDENT# ids . append ( method [ 1 ] ) #NEWLINE# #UNINDENT# return self . filter ( id__in = ids )