feat(client,setting): complete Phase 2 with partitioned client_follow_logs
- apps/client (11 models): Client, ClientContact, ClientRequirement, ClientSchoolPreference, ClientFollowLog (partitioned), ClientFollowLogAttachment, ClientViewing, ClientPropertyMatch, ClientStatusLog, ClientFavoriteFolder, ClientFolderItem - apps/client/0002 RunSQL: PARTITION BY RANGE(created_at) for client_follow_logs + monthly partitions + default; triggers update_client_last_follow + update_client_viewing_progress; partial unique index on client_no WHERE deleted_at IS NULL - apps/setting (4 models): LookupGroup, LookupItem, TenantSetting, FieldRequirementRule (tenant schema only per spec) manage.py check green; all 9 Phase 2 apps complete.
This commit is contained in:
114
apps/setting/migrations/0001_initial.py
Normal file
114
apps/setting/migrations/0001_initial.py
Normal file
@@ -0,0 +1,114 @@
|
||||
# Generated by Django 4.2.16 on 2026-04-29 09:33
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('org', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='FieldRequirementRule',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('module', models.CharField(choices=[('property', '房源'), ('client', '客源')], max_length=20)),
|
||||
('entity_type', models.CharField(choices=[('residential', '住宅'), ('villa', '别墅'), ('commercial_residential', '商住'), ('shop', '商铺'), ('office', '写字楼'), ('other', '其他')], max_length=50)),
|
||||
('trade_status', models.CharField(choices=[('sale', '出售'), ('rent', '出租'), ('sale_rent', '租售'), ('*', '全部')], max_length=20)),
|
||||
('field_key', models.CharField(max_length=50)),
|
||||
('requirement', models.CharField(choices=[('required', '必填'), ('optional', '选填'), ('hidden', '隐藏')], max_length=10)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'field_requirement_rules',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='LookupGroup',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('module', models.CharField(max_length=50)),
|
||||
('key', models.CharField(max_length=100)),
|
||||
('label_zh', models.CharField(max_length=50)),
|
||||
('description', models.TextField(blank=True, default='')),
|
||||
('sort_order', models.SmallIntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
options={
|
||||
'db_table': 'lookup_groups',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='TenantSetting',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('category', models.CharField(max_length=50)),
|
||||
('key', models.CharField(max_length=100)),
|
||||
('value', models.JSONField()),
|
||||
('value_type', models.CharField(choices=[('bool', '布尔'), ('int', '整数'), ('string', '字符串'), ('enum', '枚举')], max_length=20)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('updated_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_tenant_settings', to='org.staff')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'tenant_settings',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='LookupItem',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('value', models.CharField(max_length=100)),
|
||||
('label_zh', models.CharField(max_length=50)),
|
||||
('is_system', models.BooleanField(default=False)),
|
||||
('is_active', models.BooleanField(default=True)),
|
||||
('sort_order', models.SmallIntegerField(default=0)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('updated_at', models.DateTimeField(auto_now=True)),
|
||||
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='created_lookup_items', to='org.staff')),
|
||||
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='setting.lookupgroup')),
|
||||
],
|
||||
options={
|
||||
'db_table': 'lookup_items',
|
||||
},
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='lookupgroup',
|
||||
constraint=models.UniqueConstraint(fields=('module', 'key'), name='uq_lookup_groups_module_key'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='fieldrequirementrule',
|
||||
name='updated_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='updated_field_rules', to='org.staff'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='tenantsetting',
|
||||
index=models.Index(fields=['category'], name='idx_tenant_settings_cat'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='tenantsetting',
|
||||
constraint=models.UniqueConstraint(fields=('category', 'key'), name='uq_tenant_settings_cat_key'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='lookupitem',
|
||||
index=models.Index(fields=['group', 'is_active', 'sort_order'], name='idx_lookup_items_active'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='lookupitem',
|
||||
constraint=models.UniqueConstraint(fields=('group', 'value'), name='uq_lookup_items_group_value'),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name='fieldrequirementrule',
|
||||
index=models.Index(fields=['module', 'entity_type', 'trade_status'], name='idx_field_req_lookup'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='fieldrequirementrule',
|
||||
constraint=models.UniqueConstraint(fields=('module', 'entity_type', 'trade_status', 'field_key'), name='uq_field_req_quad'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
from .lookup import LookupGroup, LookupItem
|
||||
from .setting import FieldRequirementRule, TenantSetting
|
||||
|
||||
__all__ = [
|
||||
"LookupGroup",
|
||||
"LookupItem",
|
||||
"TenantSetting",
|
||||
"FieldRequirementRule",
|
||||
]
|
||||
|
||||
55
apps/setting/models/lookup.py
Normal file
55
apps/setting/models/lookup.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from django.db import models
|
||||
|
||||
from core.models.base import UUIDPrimaryKeyModel
|
||||
|
||||
|
||||
class LookupGroup(UUIDPrimaryKeyModel):
|
||||
module = models.CharField(max_length=50)
|
||||
key = models.CharField(max_length=100)
|
||||
label_zh = models.CharField(max_length=50)
|
||||
description = models.TextField(blank=True, default="")
|
||||
sort_order = models.SmallIntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "lookup_groups"
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["module", "key"], name="uq_lookup_groups_module_key"
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class LookupItem(UUIDPrimaryKeyModel):
|
||||
group = models.ForeignKey(
|
||||
LookupGroup, on_delete=models.CASCADE, related_name="items"
|
||||
)
|
||||
value = models.CharField(max_length=100)
|
||||
label_zh = models.CharField(max_length=50)
|
||||
is_system = models.BooleanField(default=False)
|
||||
is_active = models.BooleanField(default=True)
|
||||
sort_order = models.SmallIntegerField(default=0)
|
||||
created_by = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="created_lookup_items",
|
||||
)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "lookup_items"
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["group", "value"], name="uq_lookup_items_group_value"
|
||||
),
|
||||
]
|
||||
indexes = [
|
||||
models.Index(
|
||||
fields=["group", "is_active", "sort_order"],
|
||||
name="idx_lookup_items_active",
|
||||
),
|
||||
]
|
||||
75
apps/setting/models/setting.py
Normal file
75
apps/setting/models/setting.py
Normal file
@@ -0,0 +1,75 @@
|
||||
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)
|
||||
key = models.CharField(max_length=100)
|
||||
value = models.JSONField()
|
||||
value_type = models.CharField(max_length=20, choices=SettingValueType.choices)
|
||||
updated_by = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="updated_tenant_settings",
|
||||
)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "tenant_settings"
|
||||
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)
|
||||
entity_type = models.CharField(max_length=50, choices=FieldRuleEntityType.choices)
|
||||
trade_status = models.CharField(max_length=20, choices=TRADE_STATUS_CHOICES)
|
||||
field_key = models.CharField(max_length=50)
|
||||
requirement = models.CharField(
|
||||
max_length=10, choices=FieldRuleRequirement.choices
|
||||
)
|
||||
updated_by = models.ForeignKey(
|
||||
"org.Staff",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="updated_field_rules",
|
||||
)
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
db_table = "field_requirement_rules"
|
||||
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",
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user