Skip to content

Commit

Permalink
Merge pull request #1533 from gtech-mulearn:dev
Browse files Browse the repository at this point in the history
[FEAT] Add user manager
  • Loading branch information
MZaFaRM authored Nov 6, 2023
2 parents 3d45060 + 2413046 commit f6f8fd9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions db/managers/user_manager.py
Original file line number Diff line number Diff line change
@@ -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,
)
)
3 changes: 3 additions & 0 deletions db/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid

from django.db import models
from .managers import user_manager

# fmt: off
# noinspection PyPep8
Expand All @@ -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
Expand Down

0 comments on commit f6f8fd9

Please sign in to comment.