Skip to content

Commit

Permalink
feat(stats): add queryset to Stat model
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Sep 26, 2023
1 parent 0a3cba6 commit b1575aa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lacommunaute/forum_stats/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
from lacommunaute.forum_stats.enums import Period


class StatQuerySet(models.QuerySet):
def current_month_datas(self):
qs = Stat.objects.filter(period="month").order_by("-date")

if qs.exists():
return Stat.objects.filter(date=qs.first().date, period=Period.MONTH).values("name", "value", "date")

return Stat.objects.none()


class Stat(models.Model):
name = models.CharField(max_length=30, verbose_name="Nom")
date = models.DateField(verbose_name="Date")
Expand All @@ -19,3 +29,5 @@ class Meta:

def __str__(self):
return f"{self.name} - {self.date} - {self.period}"

objects = StatQuerySet().as_manager()

0 comments on commit b1575aa

Please sign in to comment.