Skip to content

Models

This module provides abstract base models and mixins for consistent model design across Django applications using drf-corekit.

BaseModel

Provides a consistent primary key field across all models.

id = models.BigAutoField(primary_key=True)

PublicIDMixin

Adds a public facing UUID identifier.

public_id = models.UUIDField(default=uuid.uuid4, unique=True)

CreatedAtMixin

Adds creation timestamp tracking.

created_at = models.DateTimeField(default=timezone.now)

LastModifiedAtMixin

Tracks last modification time automatically.

last_modified_at = models.DateTimeField(auto_now=True)

CommonModel

A standard base model combining:

  • BaseModel
  • CreatedAtMixin
  • LastModifiedAtMixin

Use this as the default base for most internal models.

CommonWithPublicIDModel

Extends CommonModel with a public UUID identifier.

AbstractUser

Abstract base user model providing auth fields, account state, and lifecycle methods. Designed to be subclassed once per project.

Inherits from BaseModel, PublicIDMixin, LastModifiedAtMixin, Django's AbstractBaseUser, and PermissionsMixin.

Usage

from drf_corekit.users import AbstractUser

class User(AbstractUser):
    user_type = models.IntegerField(
        choices=UserType.choices,
        default=UserType.USER,
    )

    class Meta(AbstractUser.Meta):
        db_table = to_app_table_name("users")

Set AUTH_USER_MODEL in your Django settings:

AUTH_USER_MODEL = "core.User"

Fields

Field Type Description
username CharField Unique login identifier
email EmailField Email address; null if not provided
is_staff BooleanField Django admin access
is_active BooleanField Account can authenticate
is_suspended BooleanField Admin-imposed block; distinct from is_active
is_scheduled_for_deletion BooleanField Queued for hard deletion by a management command
joined_at DateTimeField Account creation timestamp
verified_at DateTimeField Email verification timestamp; null until verified
suspended_at DateTimeField When suspension was applied; null if not suspended
suspension_reason CharField Admin-supplied reason; null if not suspended
deletion_scheduled_at DateTimeField When deletion was scheduled; null if not scheduled

Methods

suspend(reason=None)

Marks the account as suspended and records the timestamp and optional reason.

user.suspend(reason="Violation of terms of service")

unsuspend()

Clears suspension state and wipes the recorded reason and timestamp.

user.unsuspend()

schedule_deletion()

Flags the account for deferred hard deletion. The actual deletion is performed by a management command.

user.schedule_deletion()

cancel_deletion()

Revokes a previously scheduled deletion.

user.cancel_deletion()

email_user(subject, message, from_email=None, **kwargs)

Sends an email to the user via django.core.mail.send_mail.

user.email_user(
    subject="Your account has been suspended",
    message="Please contact support for more information.",
)

Configuration

Username field behaviour is controlled via DRF_COREKIT settings. See Configurations for details.