Source code for apps.users.managers
from django.contrib.auth.models import UserManager
from django.db import models
[docs]
class NotDeletedQuerySet(models.QuerySet):
"""
QuerySet that filters out objects which are marked as deleted.
"""
[docs]
def alive(self):
return self.filter(is_deleted=False)
[docs]
class NotDeletedManager(UserManager):
"""
Manager that uses the NotDeletedQuerySet to filter out deleted objects.
"""
[docs]
def get_queryset(self):
return NotDeletedQuerySet(self.model, using=self._db).alive()
[docs]
def create_superuser(self, username, email=None, password=None, **extra_fields):
extra_fields.setdefault("is_staff", True)
extra_fields.setdefault("is_active", True)
extra_fields.setdefault("is_superuser", True)
if extra_fields.get("is_staff") is not True:
raise ValueError("Superuser must have is_staff=True.")
if extra_fields.get("is_superuser") is not True:
raise ValueError("Superuser must have is_superuser=True.")
return self._create_user(username, email, password, **extra_fields)