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


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


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='dianpu',
            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),
    ]
