Files
Django/config/migrations/0009_gonggao_copy_pages.py

28 lines
895 B
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
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),
]