Skip to content
Snippets Groups Projects
Commit 48c6846f authored by Johannes Graf's avatar Johannes Graf
Browse files

Getters added for survey-cards

parent 001b5cb9
No related branches found
No related tags found
1 merge request!16Feature/unanswered surveys
......@@ -124,6 +124,14 @@ class CustomUser(AbstractBaseUser, PermissionsMixin): # pyright: ignore
def __str__(self) -> str:
return f"{self.name} ({self.email})"
# To see how many surveys this user has unanswered
def count_unanswered_surveys(self):
return self.survey_results.filter(is_answered=False).count()
# To get all unanswered surveys for this user
def get_unanswered_surveys(self):
return self.survey_results.filter(is_answered=False)
......@@ -201,6 +209,8 @@ class SurveyResult(models.Model):
def __str__(self) -> str:
return f"{self.user} ({self.is_answered})"
class BaseQuestionDetails(models.Model):
......
......@@ -279,4 +279,10 @@ def survey_status_view(request):
def unanswered_surveys_view(request):
return render(request, "unanswered_surveys.html")
user = request.user # Assuming the user is authenticated
unanswered_count = user.count_unanswered_surveys()
unanswered_surveys = user.get_unanswered_surveys()
return render(request, "unanswered_surveys.html", {
'unanswered_count': unanswered_count,
'unanswered_surveys': unanswered_surveys,
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment