No project description provided
Project description
django-likeit-ptbr
A simple app for Django that enables users to like and unlike any object/item within any model. It's developed on Python 3.5 & Python 3.6 for Django 2.0 and later. Adjustments made from original django-likeit
Installation
- Install django-likeit in your vilrtual env:
pip install django-likeit-ptbr
- Add the app to your settings.py
INSTALLED_APPS = [
...
"like",
...
]
- Add likeit urls to your project's
urls.pyfile:
from django.conf.urls import url, include
urlpatterns = [
...
url(r'^like/', include('like.urls')),
...
]
- Migrations:
python manage.py makemigrations like
python manage.py migrate
- Make sure you have jQuery ajax CSRF configuration right, and also you included Font Awesome in your HTML.
Usage:
Template tags:
- Get the liked objects for a given user:
{% with user_likes <user> "app_label.model" as like_list %}
{% for like_obj in like_list %}
{# do something with like_obj #}
{% endfor %}
{% endwith %}
- Given an object
objyou may show it like count like this:
<p>Like Count {{ obj|likes_count }}</p>
- Get Like instance for an object (obj) and a user (user)
{% with obj|get_like_for:user as like_object %}
...
{% endwith %}
- Like Button for an object
my_obj:
{% like_button my_obj %}
Likes Manager
- Create a Like instance for a user and object:
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='jdoe')
>>> song = Song.objects.get(pk=1)
>>> like = Like.objects.create(user, song)
or:
>>> like = Like.objects.create(user, 1, Song)
or:
>>> like = Like.objects.create(user, 1, "music.Song")
- Get the objects liked by a given user:
>>> from django.contrib.auth.models import User
>>> user = User.objects.get(username='jdoe')
>>> Like.objects.for_user(user)
>>> [<Like: Like object 1>, <Like: Like object 2>, <Like: Like object 3>]
- Now, get user liked objects belonging to a given model:
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='jdoe')
>>> Like.objects.for_user(user, model=Song)
>>> [<Like: Like object 1>, <Like: Like object 2>, <Like: Like object 3>]
- Get the liked object instances of a given model liked by any user:
>>> from music.models import Song
>>> Like.objects.for_model(Song)
>>> [<Like: Like object 1>, <Like: Like object 2>, <Like: Like object 3>]
- Get a Like instance for a given object and user:
>>> from django.contrib.auth.models import User
>>> from music.models import Song
>>> user = User.objects.get(username='jdoe')
>>> song = Song.objects.get(pk=1)
>>> like = Like.objects.get_like(user, song)
- Get all Like instances for a given object
>>> from music.models import Song
>>> song = Song.objects.get(pk=1)
>>> like = Like.objects.for_object(song)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-likeit-ptbr-0.1.2.tar.gz.
File metadata
- Download URL: django-likeit-ptbr-0.1.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cce6027bd04c5f13e84b6e32cb83cf1db9db542316b8571d1daf1b125d55080
|
|
| MD5 |
ff19e8ab5139be9bee8efcde15077dcb
|
|
| BLAKE2b-256 |
a83d82c0c1b70e21c6c07825ec447db59dbcbf8d196c457b49ae5fd92380d2df
|