From 3c66fd8ac4fbef2578d1e1a6d8a2ef11a03ff933 Mon Sep 17 00:00:00 2001 From: Hubert Jankowski Date: Sun, 30 Jan 2022 15:20:55 +0100 Subject: [PATCH] Add questions count --- templates/category.html | 2 +- templates/home.html | 2 +- templates/myTests.html | 2 +- trials/models.py | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/templates/category.html b/templates/category.html index 37d78bc..581b195 100644 --- a/templates/category.html +++ b/templates/category.html @@ -12,7 +12,7 @@
Kategoria: {{test.category}}
Próg zaliczenia: {{test.passing_score}}
-
Ilość pytań: {{test.questions|length}}
+
Ilość pytań: {{test.question_count}}
diff --git a/templates/home.html b/templates/home.html index c3078e2..d60d4ad 100644 --- a/templates/home.html +++ b/templates/home.html @@ -12,7 +12,7 @@
Kategoria: {{test.category}}
Próg zaliczenia: {{test.passing_score}}
-
Ilość pytań: {{test.questions|length}}
+
Ilość pytań: {{test.question_count}}
diff --git a/templates/myTests.html b/templates/myTests.html index 5d1bf94..0d00640 100644 --- a/templates/myTests.html +++ b/templates/myTests.html @@ -12,7 +12,7 @@
Kategoria: {{test.category}}
Próg zaliczenia: {{test.passing_score}}
-
Ilość pytań: {{test.questions|length}}
+
Ilość pytań: {{test.question_count}}
diff --git a/trials/models.py b/trials/models.py index c9be013..e0741c6 100644 --- a/trials/models.py +++ b/trials/models.py @@ -1,4 +1,6 @@ from django.db import models + +from questions.models import Question from .managers import TestManager @@ -62,6 +64,9 @@ class Test(models.Model): points += question.points return points + def question_count(self): + return Question.objects.filter(test_id=self.id).count() + def name_and_passing_score(self): return { "name": self.name, -- 2.20.1