Put short description here...
Project description
django-popularity-mixin
Simple integration between django-cacheback and django-hitcount
Authored by Basil Shubin
Requirements
You must have django-cacheback and django-hitcount both installed and configured, see the django-cacheback and django-hitcount documentation for details and setup instructions.
Installation
First install the module, preferably in a virtual environment. It can be installed from PyPI:
pip install django-popularity-mixin
Setup
Make sure the project is configured for django-cacheback and django-hitcount.
Then add the following settings:
INSTALLED_APPS += (
'popularity',
)
Usage
The popularity.views.PopularityMixin can be used to do the business-logic of counting the hits asynchronously by setting count_hit to True.
# views.py
from django.views.generic.detail import DetailView
from popularity.views import PopularityMixin
class CustomDetailView(PopularityMixin, DetailView):
count_hit = True # set to True if you want it to try and count the hit asynchronously
template_name = "template.html"
...
The popularity.viwes.PopularityMixin extends Django’s generic django.views.generic.detail.DetailView and injects an additional context variable hitcount.
<!-- template.html -->
{# the primary key for the hitcount object #}
{{ hitcount.pk }}
{# the total hits for the object #}
{{ hitcount.total_hits }}
For a more granular approach to viewing the hits for a related object you can use the get_hit_count template tag.
{# remember to load the tags first #}
{% load popularity_tags %}
{# Return total hits for an object: #}
{% get_hit_count for [object] %}
{# Get total hits for an object as a specified variable: #}
{% get_hit_count for [object] as [var] %}
{# Get total hits for an object over a certain time period: #}
{% get_hit_count for [object] within ["days=1,minutes=30"] %}
{# Get total hits for an object over a certain time period as a variable: #}
{% get_hit_count for [object] within ["days=1,minutes=30"] as [var] %}
Please see example application. This application is used to manually test the functionalities of this package. This also serves as good example…
You need Django 1.8.1 or above to run that. It might run on older versions but that is not tested.
Contributing
If you like this module, forked it, or would like to improve it, please let us know! Pull requests are welcome too. :-)
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
Built Distribution
File details
Details for the file django-popularity-mixin-0.1.7.tar.gz
.
File metadata
- Download URL: django-popularity-mixin-0.1.7.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af8c6e152a035ac31deda21b6dde515edc490d9ee73575178012d0ee4a363c4d |
|
MD5 | c08220ad72ac775c76b4867b990ee46b |
|
BLAKE2b-256 | 832b6f11776139b538a95016d6af86ef555cc1984a7bd527c40710ef7802fb41 |
File details
Details for the file django_popularity_mixin-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: django_popularity_mixin-0.1.7-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eb62df25f200da91545a11a31c5a035463ae7eef43900dc3b9869609fd87813 |
|
MD5 | cdb7b69a734313b65f039158bb8990f2 |
|
BLAKE2b-256 | 2a0404e17b45a8ab92630623e2314d5465391e1649041cf13752a3cf0048ed1e |