from django.db import migrations, models
from django.db.models import Q


def backfill_club_xq(apps, schema_editor):
    Shangpin = apps.get_model('products', 'Shangpin')
    ShangpinZhuanqu = apps.get_model('products', 'ShangpinZhuanqu')
    Shangpin.objects.filter(Q(club_id__isnull=True) | Q(club_id='')).update(club_id='xq')
    ShangpinZhuanqu.objects.filter(Q(club_id__isnull=True) | Q(club_id='')).update(club_id='xq')


class Migration(migrations.Migration):

    dependencies = [
        ('products', '0011_huiyuan_is_bundle'),
    ]

    operations = [
        migrations.AddField(
            model_name='shangpin',
            name='club_id',
            field=models.CharField(
                db_index=True,
                default='xq',
                help_text='公共商品按俱乐部隔离；历史数据默认星阙 xq',
                max_length=16,
                verbose_name='所属俱乐部',
            ),
        ),
        migrations.AddField(
            model_name='shangpinzhuanqu',
            name='club_id',
            field=models.CharField(
                db_index=True,
                default='xq',
                help_text='公共专区按俱乐部隔离；历史数据默认星阙 xq',
                max_length=16,
                verbose_name='所属俱乐部',
            ),
        ),
        migrations.RunPython(backfill_club_xq, migrations.RunPython.noop),
    ]
