From 03e12954f295662d894bc0efa65054bfd63c42b6 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 14 Jun 2021 11:49:22 +0200 Subject: [PATCH] Daily stats view. --- src/stats/admin.py | 1 + src/stats/urls.py | 1 + src/stats/views.py | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/stats/admin.py b/src/stats/admin.py index 11dfe7e89..9e5ab4744 100644 --- a/src/stats/admin.py +++ b/src/stats/admin.py @@ -10,3 +10,4 @@ class VisitsAdmin(admin.ModelAdmin): admin.site.register(models.Visits, VisitsAdmin) +admin.site.register(models.DayVisits, VisitsAdmin) diff --git a/src/stats/urls.py b/src/stats/urls.py index 80d261178..1b770a8c8 100644 --- a/src/stats/urls.py +++ b/src/stats/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path('top/', views.TopView.as_view(), name='stats_top'), + path('top/daily/', views.TopView.as_view(), name='stats_top'), ] diff --git a/src/stats/views.py b/src/stats/views.py index 4ff85f494..93cda3797 100644 --- a/src/stats/views.py +++ b/src/stats/views.py @@ -6,6 +6,7 @@ from . import models class TopView(PermissionRequiredMixin, TemplateView): + model = models.Visits permission_required = 'stats.view_visits' template_name = 'stats/top.html' @@ -13,7 +14,7 @@ class TopView(PermissionRequiredMixin, TemplateView): ctx = super().get_context_data(**kwargs) form = forms.VisitsForm(self.request.GET) assert form.is_valid() - visits = models.Visits.objects.all() + visits = self.model.objects.all() if form.cleaned_data['date_since']: visits = visits.filter(date__gte=form.cleaned_data['date_since'].replace(day=1)) if form.cleaned_data['date_until']: @@ -27,3 +28,6 @@ class TopView(PermissionRequiredMixin, TemplateView): ctx['visits'] = visits return ctx + +class DailyTopView(TopView): + model = models.DayVisits -- 2.20.1