Files
Django/shop/migrations/0004_shenhe_shezhi_club_id.py
XingQue 6515568ec0 feat: 只看审核按俱乐部隔离,商品管理支持俱乐部视图
未绑店出货开关按 club_id 配置;后台商品列表可在具体小程序下管理并切换审核展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-21 03:20:03 +08:00

45 lines
1.3 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 migrations, models
def forwards_fill_club_id(apps, schema_editor):
Model = apps.get_model('shop', 'DianpuShangpinShenheShezhi')
# 历史全局单例 → 归到星阙 xq若已有多行则只保留一条
rows = list(Model.objects.all().order_by('id'))
if not rows:
return
keep = rows[0]
keep.club_id = keep.club_id or 'xq'
keep.save(update_fields=['club_id'])
for extra in rows[1:]:
extra.delete()
def noop_reverse(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
('shop', '0003_zhi_kan_shenhe'),
]
operations = [
migrations.AddField(
model_name='dianpushangpinshenheshezhi',
name='club_id',
field=models.CharField(
db_index=True, default='xq', max_length=16, verbose_name='所属俱乐部',
),
),
migrations.RunPython(forwards_fill_club_id, noop_reverse),
migrations.AlterField(
model_name='dianpushangpinshenheshezhi',
name='club_id',
field=models.CharField(
db_index=True, default='xq', max_length=16, unique=True,
verbose_name='所属俱乐部',
),
),
]