@register.tag
def regroup(parser, token):
 bits = token.split_contents()
 if (len(bits) != 6):
  raise TemplateSyntaxError("'regroup' tag takes five arguments")
 target = parser.compile_filter(bits[1])
 if (bits[2] != 'by'):
  raise TemplateSyntaxError("second argument to 'regroup' tag must be 'by'")
 if (bits[4] != 'as'):
  raise TemplateSyntaxError("next-to-last argument to 'regroup' tag must be 'as'")
 var_name = bits[5]
 expression = parser.compile_filter(((var_name + VARIABLE_ATTRIBUTE_SEPARATOR) + bits[3]))
 return RegroupNode(target, expression, var_name)

@ register . tag def regroup ( parser , token ) : bits = token . split_contents ( ) if ( len ( bits ) != 6 ) : raise TemplateSyntaxError ( "'regroup' tag takes five arguments" ) target = parser . compile_filter ( bits [ 1 ] ) if ( bits [ 2 ] != 'by' ) : raise TemplateSyntaxError ( "second argument to 'regroup' tag must be 'by'" ) if ( bits [ 4 ] != 'as' ) : raise TemplateSyntaxError ( "next-to-last argument to 'regroup' tag must be 'as'" ) var_name = bits [ 5 ] expression = parser . compile_filter ( ( ( var_name + VARIABLE_ATTRIBUTE_SEPARATOR ) + bits [ 3 ] ) ) return RegroupNode ( target , expression , var_name )
regroups a list of alike objects by a common attribute .