Files
fonrey/apps/setting/models/setting.py

126 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from django.db import models
from core.enums import (
FieldRuleEntityType,
FieldRuleModule,
FieldRuleRequirement,
SettingValueType,
)
from core.models.base import UUIDPrimaryKeyModel
TRADE_STATUS_CHOICES = (
("sale", "出售"),
("rent", "出租"),
("sale_rent", "租售"),
("*", "全部"),
)
class TenantSetting(UUIDPrimaryKeyModel):
category = models.CharField(
max_length=50,
verbose_name="配置分类",
help_text="client / property / showroom",
)
key = models.CharField(
max_length=100,
verbose_name="配置 key",
help_text="如 duplicate_check_scope",
)
value = models.JSONField(
verbose_name="配置值",
help_text='JSONB统一格式 {"v": <value>}',
)
value_type = models.CharField(
max_length=20,
choices=SettingValueType.choices,
verbose_name="值类型",
help_text="bool / int / string / enum用于前端渲染控件",
)
updated_by = models.ForeignKey(
"org.Staff",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="updated_tenant_settings",
verbose_name="最后修改人",
)
updated_at = models.DateTimeField(
auto_now=True,
verbose_name="更新时间",
)
class Meta:
db_table = "tenant_settings"
verbose_name = "租户设置"
verbose_name_plural = "租户设置"
constraints = [
models.UniqueConstraint(
fields=["category", "key"], name="uq_tenant_settings_cat_key"
),
]
indexes = [
models.Index(fields=["category"], name="idx_tenant_settings_cat"),
]
class FieldRequirementRule(UUIDPrimaryKeyModel):
module = models.CharField(
max_length=20,
choices=FieldRuleModule.choices,
verbose_name="模块",
help_text="property / clientMVP 仅 property",
)
entity_type = models.CharField(
max_length=50,
choices=FieldRuleEntityType.choices,
verbose_name="实体类型",
help_text="与 property.property_type 值域完全一致residential/villa/commercial_residential/shop/office/other",
)
trade_status = models.CharField(
max_length=20,
choices=TRADE_STATUS_CHOICES,
verbose_name="交易状态",
help_text="sale=出售 / rent=出租 / sale_rent=租售 / *=全部fallback 通配)",
)
field_key = models.CharField(
max_length=50,
verbose_name="字段 key",
help_text="如 orientation / decoration / floor / building_area",
)
requirement = models.CharField(
max_length=10,
choices=FieldRuleRequirement.choices,
verbose_name="规则",
help_text="required=必填 / optional=选填 / hidden=隐藏",
)
updated_by = models.ForeignKey(
"org.Staff",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="updated_field_rules",
verbose_name="最后修改人",
)
updated_at = models.DateTimeField(
auto_now=True,
verbose_name="更新时间",
)
class Meta:
db_table = "field_requirement_rules"
verbose_name = "字段必填规则"
verbose_name_plural = "字段必填规则"
constraints = [
models.UniqueConstraint(
fields=["module", "entity_type", "trade_status", "field_key"],
name="uq_field_req_quad",
),
]
indexes = [
models.Index(
fields=["module", "entity_type", "trade_status"],
name="idx_field_req_lookup",
),
]