From 9d2abe8544a86f4068316b8b18594b6a3bc96fb8 Mon Sep 17 00:00:00 2001 From: Muhammed Zafar Date: Mon, 6 Nov 2023 15:46:47 +0530 Subject: [PATCH] [FEAT] Add user manager --- db/managers/user_manager.py | 16 ++++++++++++++++ db/user.py | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 db/managers/user_manager.py diff --git a/db/managers/user_manager.py b/db/managers/user_manager.py new file mode 100644 index 00000000..9368ff21 --- /dev/null +++ b/db/managers/user_manager.py @@ -0,0 +1,16 @@ +from django.db import models + + +class ActiveUserManager(models.Manager): + def get_queryset(self): + # This will return only the users where deleted_at, deleted_by, suspended_at, and suspended_by are NULL + return ( + super() + .get_queryset() + .filter( + deleted_at__isnull=True, + deleted_by__isnull=True, + suspended_at__isnull=True, + suspended_by__isnull=True, + ) + ) diff --git a/db/user.py b/db/user.py index 1eb57f36..2dd211ad 100644 --- a/db/user.py +++ b/db/user.py @@ -1,6 +1,7 @@ import uuid from django.db import models +from .managers import user_manager # fmt: off # noinspection PyPep8 @@ -25,6 +26,8 @@ class User(models.Model): suspended_by = models.ForeignKey("self", on_delete=models.CASCADE, blank=True, null=True, related_name="suspended_by_user", db_column="suspended_by") deleted_at = models.DateTimeField(blank=True, null=True) deleted_by = models.ForeignKey("self", on_delete=models.CASCADE, blank=True, null=True, related_name="deleted_by_user", db_column="deleted_by") + objects = user_manager.ActiveUserManager() + every = models.Manager() class Meta: managed = False