from django import template

register = template.Library()


@register.filter
def star_rating(value):
    """
    Display a star rating (1-5) as star characters.
    
    Usage: {{ comment.rating|star_rating }}
    
    Returns: ★★★☆☆ for rating 3, ★★★★★ for rating 5, etc.
    """
    try:
        rating = int(value)
    except (TypeError, ValueError):
        return ''
    
    if rating < 1 or rating > 5:
        return ''
    
    stars = '★' * rating
    empty_stars = '☆' * (5 - rating)
    
    return f"{stars}{empty_stars}"
