I want to compare a variable in django template. Problem is as follows. I am loading a set of photos in a page. When a template is loaded, it contains all the photos. But when a user clicks on edit button, i want that only properties of photos saved by that user should be in editable mode.
In my template i have following
{% for img in images.object_list %}
<!-- EDIT VIEW -->
{% if view == "edit" %}
{% if user_id_log == img.image.name %}
<<Load Photos if user id matches with logged in user>>
{% else %}
<<Skip that photo>>
Last line written above is not working.
user_id_log -- User id of logged in user. Passing it from a view in render_to_response method
img.image.name -- Contains user id who created that photo.
images.object_list is list of image objects.
Please let me know how can i accomplish this
Added
I am passing user_id_log as int after typecasting it in view.py Also, img.name is also int in Database
Views.py
def album(request, pk, view="thumbnails"):
num_images = 30
if view == "full": num_images = 10
album = Album.objects.get(pk=pk)
images = album.image_set.all()
user_id = int(request.user.id)
# add list of tags as string and list of album names to each image object
for img in images.object_list:
tags = [x[1] for x in img.tags.values_list()]
img.tag_lst = join(tags, ', ')
img.album_lst = [x[1] for x in img.albums.values_list()]
d = dict(user_id_log=user_id,album=album, images=images, user=request.user, view=view,
albums=Album.objects.all(),
backurl=request.META["HTTP_REFERER"],media_url=MEDIA_URL)
d.update(csrf(request))
return render_to_response("photo/album.html", d)