템플릿 태그에서 |
문자 뒤에 사용하는 필터
기존 pybo는 페이지가 넘어가도 게시물 번호가 다시 1부터 시작함. 해결 필요
페이지 별 질문글 번호 역순 정렬하기
번호 = 전체건수 - 시작인덱스 - 현재인덱스 + 1
C:\projects\mysite\pybo\templatetags
이 디렉토리에만 생성 가능. pybo앱 하위에!!
pybo_filter.py
파일 작성
from django import template
register = template.Library()
@register.filter
def sub(value, arg):
return value - arg
로드하기
템플릿 상단에 {% load pybo_filter %}
코드는 {{ question_list.paginator.count|sub:question_list.start_index|sub:forloop.counter0|add:1 }}
:: 전체건수 count - 시작인덱스 - 현재인덱스 + 1
{% if question.answer_set.count > 0 %}
<span class="text-danger small ml-2">{{ question.answer_set.count }}</span>
{% endif %}