from django template import Library from django import template from i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from django.template import Library
from django import template
from images.models import Images
register = template.Library()
@register.tag(name="images_counter")
def images_counter(parser, token):
return ImageCounterNode(len(Images.objects.all()))
class ImageCounterNode(template.Node):
def __init__(self, counter):
self.counter = counter
def render(self, context):
return self.counter