Skip to main content

Django app providing view interface to django-secretballot.

Project description

Django Likes
**Django app providing view interface to django-secretballot.**

.. image::

.. image::

This app utilizes `Django Secretballot <>`_ to provide Facebook or Google+1 style item liking of Django model objects. Authenticated or anonymous users are allowed to like any given object only once.

.. contents:: Contents
:depth: 5


#. Python 2.7, 3.5+

#. Django 1.11, 2.0+

#. django-secretballot 1.0.0

#. Install or add ``django-likes`` to your Python path.

#. Configure ``django-secretballot`` as described `here <>`_.

#. Add ``likes`` to your ``INSTALLED_APPS`` setting.

#. Add likes url include to your project's ```` file::

url('likes/', include('likes.urls')),

#. Add ``likes.middleware.SecretBallotUserIpUseragentMiddleware`` to your ``MIDDLEWARE_CLASSES`` setting, i.e.::

...other middleware classes...

#. Make sure ``django.template.context_processors.request`` is in your ``TEMPLATES['OPTIONS']['context_processors']`` setting.


Template Tags

{% likes object %}
django-likes provides an inclusion tag called ``likes`` which renders a like button for any given object, displaying the number of likes and allowing users to like the object. The tag accepts as first argument the object for which to display and on which to apply likes, i.e.::

{% load likes_inclusion_tags %}

...some html...

{% likes object %}

...some more html...

``object`` here is any Django model object for which `django-secretballot <>`_ voting has been enabled. In the background the like is uniquely addressed to the object using its content type and object id.

.. note::

In order for the ``likes`` tag to work the request object needs to be available within the template's context. Thus you have to use `RequestContext <>`_ in your views to construct context, which, combined with the ``django.core.context_processors.request`` context processor, will ensure the request object is available as part of the context.

The template tag supports AJAX style liking. To enable it you need ensure django-likes' static media is accessible, see `managing static files <>`_. You also need to load jQuery somewhere in your template, e.g.::

<script type="text/javascript" src=""></script>

To determine whether or not liking/voting should be enabled on an object, connect a signal handler to the ``likes.signals.likes_enabled_test`` signal, raising a ``likes.exceptions.LikesNotEnabledException`` if liking should be disabled. The default behaviour is that liking is enabled for all secretballot enabled objects.

To determine whether or not the current requesting user can vote, connect a signal handler to the ``likes.signals.can_vote_test`` signal, raising a ``likes.exceptions.CannotVoteException`` if the current user should not be allowed to vote (the handler receives a request object). The default behaviour is that all users can vote except if they have previously voted on the object in question.

Praekelt Consulting
* Shaun Sephton
* Jonathan Bydendyk
* Hedley Roos


#. Python 3.7 support.
#. Django 2.1 compatibility.

#. Python 3.5 support.
#. Django 2.0 compatibility.

#. Django 1.11 compatibility.

#. Django 1.8 - 1.10 compatibility. Since `django-secretballot` has deprecated support for Django < 1.8 we follow suit.

#. Django 1.6 compatibility.

0.1 (2013-11-08)
#. Refactor `live` to `on` so a jQuery >= 1.9 can be used.
#. Translations.

0.0.12 (2013-08-16)
#. Only use jQuery if it is present.

0.0.11 (2013-01-31)
#. Remove error thrown by middleware when there is no user agent and use alternative to prevent spambot likes. This is a django-secretballot bug.

0.0.10 (2012-10-08)
#. Added ``object_liked`` signal that is sent on like.

0.0.9 (2012-09-28)
#. Added ability to specify a template to be rendered for ``likes`` inclusion tag.

0.0.8 (2012-08-20)
#. Updated ``likes_enabled_test`` and ``can_vote_test`` signals to send through sender, thereby allowing listeners to listen to specific senders.

0.0.7 (2012-08-20)
#. Revert to vote_total on inclusion tag.

0.0.6 (2012-07-24)
#. Allow for downvotes.

0.0.5 (2011-09-15)
#. Corrected manifest to include missing static resources.

0.0.4 (2011-09-14)
#. Documentation, number of fixes.

#. Handle multiple likes buttons on the same page
#. Remove dependency on jmbo
#. Unit tests

#. Prevent local cache on like redirect.

#. Initial release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-likes-2.0.1.tar.gz (10.6 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page