Daily stats view.
authorRadek Czajka <rczajka@rczajka.pl>
Mon, 14 Jun 2021 09:49:22 +0000 (11:49 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Mon, 14 Jun 2021 09:49:22 +0000 (11:49 +0200)
src/stats/admin.py
src/stats/urls.py
src/stats/views.py

index 11dfe7e..9e5ab47 100644 (file)
@@ -10,3 +10,4 @@ class VisitsAdmin(admin.ModelAdmin):
 
 
 admin.site.register(models.Visits, VisitsAdmin)
+admin.site.register(models.DayVisits, VisitsAdmin)
index 80d2611..1b770a8 100644 (file)
@@ -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'),
 ]
index 4ff85f4..93cda37 100644 (file)
@@ -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