# Generated by Django 2.2.16 on 2021-03-23 07:46

from django.db import migrations, models


def init_alias_name(apps, schema_editor):
    LocationMemberShip = apps.get_model('location', 'LocationMemberShip')
    lmss = LocationMemberShip.objects.all()
    print(dir(LocationMemberShip))
    for lms in lmss:
        if lms.member_id == lms.location.owner_id:
            lms.alias_name = lms.location.name
        else:
            lms.alias_name = '%s的"%s"' % (
                lms.location.owner.real_name,
                lms.location.name
            )


class Migration(migrations.Migration):

    dependencies = [
        ('location', '0007_auto_20210317_1537'),
    ]

    operations = [
        migrations.AddField(
            model_name='locationmembership',
            name='alias_name',
            field=models.CharField(default='', max_length=128),
        ),
        migrations.RunPython(init_alias_name)
    ]
