from django.db import migrations def copy_gonggao_to_other_pages(apps, schema_editor): """将 order_pool 公告复制到 accept_order / merchant_home(仅当目标页尚无记录)。""" Gonggao = apps.get_model('config', 'Gonggao') for pk in ('accept_order', 'merchant_home'): for row in Gonggao.objects.filter(page_key='order_pool'): if Gonggao.objects.filter(club_id=row.club_id, page_key=pk).exists(): continue Gonggao.objects.create( club_id=row.club_id, page_key=pk, NoticeType=row.NoticeType, Content=row.Content or '', ) class Migration(migrations.Migration): dependencies = [ ('config', '0008_gonggao_page_key'), ] operations = [ migrations.RunPython(copy_gonggao_to_other_pages, migrations.RunPython.noop), ]