Skip to content

Commit

Permalink
Add abstract=True
Browse files Browse the repository at this point in the history
  • Loading branch information
mjnaderi committed Sep 13, 2022
1 parent 010a351 commit ce49b62
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions django_visit_count/models.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit ce49b62

Please sign in to comment.