import os
import random

from django.db import migrations


def fix_level(apps, schema_editor):
    Level = apps.get_model('app', 'Level')
    Subject = apps.get_model('app', 'Subject')
    Grade = apps.get_model('app', 'Grade')
    Ability = apps.get_model('app', 'Ability')
    Price = apps.get_model('app', 'Price')
    Region = apps.get_model('app', 'Region')

    chinanums = '一二三四五六七八九十'
    commission_percentages = [10,10,10,10,10,10,10,10,10,10]
    region = Region.objects.get(name='许昌市')
    region.opened = True
    region.save()
    abilities = Ability.objects.all()

    print("修正教师等级")
    for i in range(0,len(chinanums)):
        level, _ = Level.objects.get_or_create(id=i+1, defaults={'level_order': 0})
        level.name = chinanums[i]+'级'
        level.save()
        #print(" {level_name}".format(level_name=level.name))
        p = 100 + i * 30
        for ability in abilities:
            c = p + random.randint(0, 10) * 10
            price, _ = Price.objects.get_or_create(region=region, level=level, ability=ability,
                                                   defaults={'price': c})
            price.price = c
            price.commission_percentage = commission_percentages[i]
            price.save()


class Migration(migrations.Migration):
    dependencies = [
        ('app', '0148_auto_20160615_1200'),
    ]

    operations = [
        migrations.RunPython(fix_level),
    ]

@@ -421,36 +421,106 @@
  = %5B
-10,10,10,10,10,10,10,10,10,1
+20,20,20,20,20,20,20,20,20,20%5D%0A    price_cfg = %5B2000,3000,4000,5000,6000,7000,8000,9000,10000,1100
 0%5D%0A 
@@ -643,24 +643,26 @@
 s.all()%0A%0A   
+ #
  print(%22%E4%BF%AE%E6%AD%A3%E6%95%99%E5%B8%88
@@ -913,33 +913,8 @@
 e))%0A
-        p = 100 + i * 30%0A
     
@@ -964,37 +964,19 @@
  = p
- + random.randint(0, 10) * 10
+rice_cfg%5Bi%5D
 %0A   

modify numbers