Hello,
I need to retrieve an optional number saved in DB , to a custom template tag i made . which to retrieve , a variable ( a photo ID ) included in this Gallery . within the gallery loop .
{% get_latest_photo {{photo.id}} %}
How to accomplish that ?!
P.s : I know that can be done with inclusion tag , but in the present time how to make it fix this one !
Edit the template html file :
{% for album in albumslist %}
{% get_latest_photo photo.id %}
{% for photo in recent_photos %}
<img src='{% thumbnail photo.image 200x80 crop,upscale %}' alt='{{ photo.title }}' />
{% endfor %}
{{ album.title }}
{% endfor %}
templatetag
from django.template import Library, Node
from akari.main.models import *
from django.db.models import get_model
register = Library()
class LatestPhotoNode(Node):
def __init__(self, num):
self.num = num
def render(self, context):
photo = Photo.objects.filter(akar=self.num)[:1]
context['recent_photos'] = photo
return ''
def get_latest_photo(parser, token):
bits = token.contents.split()
return LatestPhotoNode(bits[1])
get_latest_photo = register.tag(get_latest_photo)
P.s Its working very well when i replace album.id (in {% get_latest_photo photo.id %} ) with a number which acts as an album id and retrieve the photo from .
Regards H. M.