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.
PublicIDMixin¶
Adds a public facing UUID identifier.
CreatedAtMixin¶
Adds creation timestamp tracking.
LastModifiedAtMixin¶
Tracks last modification time automatically.
CommonModel¶
A standard base model combining:
BaseModelCreatedAtMixinLastModifiedAtMixin
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:
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.
unsuspend()¶
Clears suspension state and wipes the recorded reason and timestamp.
schedule_deletion()¶
Flags the account for deferred hard deletion. The actual deletion is performed by a management command.
cancel_deletion()¶
Revokes a previously scheduled 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.