Skip to content

Commit

Permalink
Add a tag to get who likes a given object
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman committed Sep 5, 2012
1 parent 627b7b0 commit 1bd8f2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog.rst
Expand Up @@ -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
-----

Expand Down
12 changes: 12 additions & 0 deletions docs/templatetags.rst
Expand Up @@ -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
-----------

Expand Down
8 changes: 8 additions & 0 deletions phileo/templatetags/phileo_tags.py
Expand Up @@ -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):
Expand Down

0 comments on commit 1bd8f2e

Please sign in to comment.