# 自动过审由「总开关」改为「按提现身份勾选」 from django.db import migrations, models def forwards_bool_to_leixings(apps, schema_editor): ClubWithdrawConfig = apps.get_model('jituan', 'ClubWithdrawConfig') # 若旧开关已开:默认放开全部身份,避免线上行为突然变严 all_leixings = [1, 2, 3, 4, 5, 6] for row in ClubWithdrawConfig.objects.all(): if getattr(row, 'auto_pass_audit', False): row.auto_pass_leixings = list(all_leixings) else: row.auto_pass_leixings = [] row.save(update_fields=['auto_pass_leixings']) def backwards_leixings_to_bool(apps, schema_editor): ClubWithdrawConfig = apps.get_model('jituan', 'ClubWithdrawConfig') for row in ClubWithdrawConfig.objects.all(): row.auto_pass_audit = bool(row.auto_pass_leixings) row.save(update_fields=['auto_pass_audit']) class Migration(migrations.Migration): dependencies = [ ('jituan', '0024_club_withdraw_auto_pass_audit'), ] operations = [ migrations.AddField( model_name='clubwithdrawconfig', name='auto_pass_leixings', field=models.JSONField(blank=True, default=list, verbose_name='自动过审身份'), ), migrations.RunPython(forwards_bool_to_leixings, backwards_leixings_to_bool), migrations.RemoveField( model_name='clubwithdrawconfig', name='auto_pass_audit', ), ]