custom_tags.py:
@register.filter
def completed(student, level):
return Task.objects.filter(student=student,level=level).count()
@register.filter
def alltodos(level):
return ToDo.objects.filter(level=level).count()
模板:
# I load this at the top
{% load custom_tags %}
{% for level in levels %}
{% completed student level as completed %}
{% alltodos level as todos %}
{% if completed == todos %}
<li>
<a href="javascript:;"><img src="{{
level.badge.url }}" alt="" /></a>
</li>
{% else %}
<li>
<a href="javascript:;"><img src="{{
level.locked_badge.url }}" alt="" /></a>
</li>
{% endif %}
{% endfor %}
自定义模板标签有麻烦。如果所有待办事项都返回并且任务编号区域相同,我想显示某种徽章或锁定的徽章。它显示了自定义模板标签的错误。基本上,如果待办事项完成,则将其另存为任务。我正在检查特定级别的所有待办事项是否已完成