Skip to content

Commit

Permalink
add current site manager
Browse files Browse the repository at this point in the history
  • Loading branch information
etchegom committed Jan 13, 2025
1 parent c3716ae commit 88889d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
15 changes: 15 additions & 0 deletions recoco/apps/hitcount/managers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.managers import CurrentSiteManager
from django.db import models


Expand All @@ -17,3 +18,17 @@ def for_context_object(self, context_object) -> models.QuerySet:

def for_user(self, user) -> models.QuerySet:
return self.filter(hits__user=user)


class HitCountOnSiteManagerBase(CurrentSiteManager):
pass


HitCountOnSiteManager = HitCountOnSiteManagerBase.from_queryset(HitCountQuerySet)


class HitCountManagerBase(models.Manager):
pass


HitCountManager = HitCountManagerBase.from_queryset(HitCountQuerySet)
5 changes: 3 additions & 2 deletions recoco/apps/hitcount/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.utils.translation import gettext_lazy as _
from model_utils.models import TimeStampedModel

from .managers import HitCountQuerySet
from .managers import HitCountManager, HitCountOnSiteManager


class HitCount(TimeStampedModel):
Expand All @@ -30,7 +30,8 @@ class HitCount(TimeStampedModel):
context_object_id = models.PositiveIntegerField(null=True, blank=True)
context_object = GenericForeignKey("context_object_ct", "context_object_id")

objects = HitCountQuerySet.as_manager()
objects = HitCountManager()
on_site = HitCountOnSiteManager()

class Meta:
verbose_name = _("hit count")
Expand Down
2 changes: 1 addition & 1 deletion recoco/apps/hitcount/tests/test_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.django_db
def test_manager():
def test_manager_queryset():
contact = baker.make(Contact)
project = baker.make(Project)
resource = baker.make(Task)
Expand Down

0 comments on commit 88889d4

Please sign in to comment.