Add count helper methods to User model

This commit is contained in:
Zaki Benaissa 2024-01-09 19:22:13 +01:00
parent 2ad66680dd
commit 0cbdf3ed47

View File

@ -81,6 +81,18 @@ 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)