feat(common): 建立公共归属与日志基础能力
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
"""跨业务应用复用的抽象模型。"""
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
|
||||
class TimeStampedModel(models.Model):
|
||||
"""统一维护创建和更新时间,避免各业务模型重复声明。"""
|
||||
|
||||
created_at = models.DateTimeField("创建时间", auto_now_add=True)
|
||||
updated_at = models.DateTimeField("更新时间", auto_now=True)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class UserOwnedModel(TimeStampedModel):
|
||||
"""为用户私有数据提供显式归属;审计数据存在时禁止删除用户。"""
|
||||
|
||||
owner = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.PROTECT,
|
||||
related_name="%(app_label)s_%(class)s_items",
|
||||
verbose_name="所属用户",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
Reference in New Issue
Block a user