minor changes

This commit is contained in:
y938 2024-04-01 14:09:00 +03:00
parent 4e323fe8d7
commit 05b07c2703
2 changed files with 12 additions and 15 deletions

View File

@ -54,6 +54,15 @@ class CustomUserManager(UserManager):
).distinct() # distinct() is often necessary with Q lookups
return queryset
def get_student_count(self):
return self.model.objects.filter(is_student=True).count()
def get_lecturer_count(self):
return self.model.objects.filter(is_lecturer=True).count()
def get_superuser_count(self):
return self.model.objects.filter(is_superuser=True).count()
GENDERS = (("M", "Male"), ("F", "Female"))
@ -85,18 +94,6 @@ class User(AbstractUser):
full_name = self.first_name + " " + self.last_name
return full_name
@classmethod
def get_student_count(cls):
return cls.objects.filter(is_student=True).count()
@classmethod
def get_lecturer_count(cls):
return cls.objects.filter(is_lecturer=True).count()
@classmethod
def get_superuser_count(cls):
return cls.objects.filter(is_superuser=True).count()
def __str__(self):
return "{} ({})".format(self.username, self.get_full_name)

View File

@ -27,9 +27,9 @@ def dashboard_view(request):
logs = ActivityLog.objects.all().order_by("-created_at")[:10]
gender_count = Student.get_gender_count()
context = {
"student_count": User.get_student_count(),
"lecturer_count": User.get_lecturer_count(),
"superuser_count": User.get_superuser_count(),
"student_count": User.objects.get_student_count(),
"lecturer_count": User.objects.get_lecturer_count(),
"superuser_count": User.objects.get_superuser_count(),
"males_count": gender_count["M"],
"females_count": gender_count["F"],
"logs": logs,