Permalink
Browse files

Add a tag to get who likes a given object

  • Loading branch information...
1 parent 627b7b0 commit 1bd8f2e87315d0a15e446093f9baa7ab5d6854b8 @paltman paltman committed Sep 5, 2012
Showing with 25 additions and 0 deletions.
  1. +5 −0 docs/changelog.rst
  2. +12 −0 docs/templatetags.rst
  3. +8 −0 phileo/templatetags/phileo_tags.py
View
@@ -3,6 +3,11 @@
ChangeLog
=========
+0.5
+---
+
+- Added a `who_likes` template tag that returns a list of `Like` objects for given object
+
0.4.1
-----
View
@@ -3,6 +3,18 @@
Filters
=======
+who_likes
+---------
+
+An assignment tag that fetches a list of likes for a given object::
+
+ {% who_likes car as car_likes %}
+
+ {% for like in car_likes %}
+ <div class="like">{{ like.user }} likes {{ car }}</div>
+ {% endfor %}
+
+
likes_count
-----------
@@ -10,6 +10,14 @@
register = template.Library()
+@register.assignment_tag
+def who_likes(athlete):
+ return Like.objects.filter(
+ receiver_content_type=ContentType.objects.get_for_model(athlete),
+ receiver_object_id=athlete.pk
+ )
+
+
class LikesNode(template.Node):
def __init__(self, user, model_list, varname):

0 comments on commit 1bd8f2e

Please sign in to comment.