diff --git a/django_visit_count/models.py b/django_visit_count/models.py index 6c22849..777053e 100644 --- a/django_visit_count/models.py +++ b/django_visit_count/models.py @@ -1,15 +1,17 @@ from django.db import models -from django.db.models import F from django.utils.translation import gettext_lazy as _ from .app_settings import VISIT_COUNT_DEFAULT_SESSION_DURATION from .utils import is_new_visit -class VisitCountMixin: +class VisitCountMixin(models.Model): visit_count = models.PositiveIntegerField(default=0, help_text=_("Visit count")) + class Meta: + abstract = True + def count_visit(self, request, session_duration=VISIT_COUNT_DEFAULT_SESSION_DURATION): if is_new_visit(request, self, session_duration=session_duration): - self.visit_count = F("visit_count") + 1 + self.visit_count = models.F("visit_count") + 1 self.save(update_fields=["visit_count"])