Django Visit Count
Count visits using cache for Django models.
Installation
-
Set-up Django's cache framework.
-
Install the Python package.
pip install django_visit_count
Usage
Use VisitCountMixin. It adds a visit_count field to your model.
from django_visit_count.mixins import VisitCountMixin
class MyBlogPost(VisitCountMixin, models.Model):
...
Create and run migrations on your model.
$ python manage.py makemigrations my_blog_app
$ python manage.py migrate my_blog_app
Count visits in your view like this:
def view_blog_post(request, post_id):
post = get_object_or_404(MyBlogPost, pk=post_id)
post.count_visit(request)
...
Advanced Usage
If you need more control, you can use is_new_visit function.
class MyBlogPost(models.Model):
total_visits = models.PositiveIntegerField(default=0)
...
from django_visit_count.utils import is_new_visit
def view_blog_post(request, post_id):
post = get_object_or_404(MyBlogPost, pk=post_id)
if is_new_visit(request, post):
post.total_visits = F("total_visits") + 1
post.save(update_fields=["total_visits"])
...
You can pass an optional keyword argument session_duration (integer, number of seconds)
to count_visit or is_new_visit.
Settings
Default settings:
VISIT_COUNT_DEFAULT_SESSION_DURATION = 5 * 60 # seconds
Development
- Install development dependencies in your virtualenv with
pip install -e '.[dev]' - Install pre-commit hooks using
pre-commit install.
License
MIT
Metadata
Release files for django-visit-count 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_visit_count-1.2.1.tar.gz | 4.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_visit_count-1.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / django_visit_count-1.2.1.tar.gz
| Download URL | django_visit_count-1.2.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dc57575ba9dd7c753105658f09699fcc02ed743a02f02cc9dd581d628665e58
|
|
BLAKE2b-256 checksum How to use checksums |
9cbf2802566d8446ec1c6687f46834a75089879831f002ab70b80acd977dbaaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / django_visit_count-1.2.1-py3-none-any.whl
| Download URL | django_visit_count-1.2.1-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ac1c624dc34148d9cf711d5933c7be726daa8e58a486149851fe53ac94c9b8b
|
|
BLAKE2b-256 checksum How to use checksums |
b9d1aee157374b4704473b3c6bceaa8cf2d335d2020d7608d100788ffc5936bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Security for django-visit-count 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.