Skip to main content

Django likes app

Project description

Build status Code health Python versions Requirements Status Software license PyPI downloads Code coverage

django-ok-likes is a liking app for Django, which allows users “like” and “unlike” any model instance. All functionality provides through django-rest-framework API views. Template tags and jinja’s global functions provide the ability to see who liked an object, which objects were liked by current user and count of likes for a given object.


Install with pip:

pip install django-ok-likes



Make migrations:

python migrate

Add likes.api.urls to your project urlpatterns:

urlpatterns = [
    path('api/v1/', include('likes.api.urls')),

Available settings

Add the models that you want to like to LIKES_MODELS in your settings file:

    "app.Model": {
        'serializer': 'app.api.serializer.YourModelSerializer'

You can set any pagination class for ListAPIView:

LIKES_REST_PAGINATION_CLASS = 'core.api.pagination.MyResponsePagination'



Base endpoints

  1. /api/v1/likes/list/ - List API View to return all likes for authenticated user.

    You can set serializer for each model in LIKES_MODELS setting to use it for content object serialization, otherwise, you will get an id of content object.

    For example:

        "article.Article": {
            'serializer': 'article.api.serializers.ArticleSerializer'

    Use GET parameter search to filter by a content type’s model: /api/v1/likes/list/?search=article

  2. /api/v1/likes/count/ - API View to return count of likes for authenticated user.

  3. /api/v1/likes/is/ - API View to check is given elements are liked by authenticated user. As result, you will get a list of ids.

    Possible payload:

        "type": 'app_label.model',  # '.'.join(object_ct.natural_key())
        "ids": [1,2,3]

    Possible result:

        "ids": [1,3]
  4. /api/v1/likes/toggle/ - API View to like-unlike a given object by authenticated user.

    Possible payload:

        "type": 'app_label.model',  # '.'.join(object_ct.natural_key())
        "id": 1

    Possible result:

        "is_liked": true



Returns a count of likes for a given object:

{{ object|likes_count }}

Template Tags


Returns a queryset of users, who liked a given object:

{% who_liked object as fans %}

{% for user in fans %}
    <div class="like">{{ user.get_full_name }} likes {{ object }}</div>
{% endfor %}


Returns a queryset of likes for a given user:

{% likes request.user as user_likes %}
{% for like in user_likes %}
    <div>{{ like }}</div>
{% endfor %}


Returns a bool value, which says is a given object liked by a given user:

{% is_liked object request.user as liked %}

Jinja global functions


The same as the likes_count filter.


{{ get_likes_count(object) }}


The same as the who_liked tag.


{{ get_who_liked(object) }}


The same as the likes tag.


{{ get_likes(request.user) }}


The same as the is_liked tag.


{{ get_is_liked(object, request.user) }}



A signal, which sents immediately after the object was liked and provides the single kwarg of created Like instance.


A signal, which sents immediately after the object was unliked and provides the single kwarg of an object.

Project details

Download files

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

Source Distribution

django-ok-likes-0.7.4.tar.gz (14.5 kB view hashes)

Uploaded source

Built Distribution

django_ok_likes-0.7.4-py3-none-any.whl (20.4 kB view hashes)

Uploaded py3

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