Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # templatetags/utils.py
- register = Library()
- @register.filter
- def stars(value):
- max_val = 5
- int_val = int(value)
- difference = value - int_val
- output = ''
- for c in range(int_val):
- output+='f'
- if difference:
- output+='h'
- for d in range(max_val-len(output)):
- output+='e'
- return output
- # template
- {% load utils %}
- {% for star in rank|stars %}
- {% if star == 'f' %}
- <i class="fa fa-star" aria-hidden="true"></i>
- {% elif star == 'h' %}
- <i class="fa fa-star-half-o" aria-hidden="true"></i>
- {% elif star == 'e' %}
- <i class="fa fa-star-o" aria-hidden="true"></i>
- {% endif %}
- {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement