@register.filter
def as_stars(value):
 num_stars_to_class = {0: '', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five'}
 num_stars = int(round((value or 0.0)))
 return num_stars_to_class.get(num_stars, '')

@ register . filter def as_stars ( value ) : num_stars_to_class = { 0 : '' , 1 : 'One' , 2 : 'Two' , 3 : 'Three' , 4 : 'Four' , 5 : 'Five' } num_stars = int ( round ( ( value or 0.0 ) ) ) return num_stars_to_class . get ( num_stars , '' )
convert a float rating between 0 and 5 to a css class the css class name is the number of stars to be displayed .