upgrade_20180223.py 894 B

12345678910111213141516171819202122232425262728293031
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. import os
  4. import sys
  5. import datetime
  6. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  7. sys.path.insert(0, PROJECT_ROOT)
  8. from script.base import *
  9. init_env(interactive=True)
  10. from apps.web.user.models import RechargeRecord, ConsumeRecord, MyUser
  11. from apps.web.device.models import Group
  12. # 将充值记录的总数从币数改为钱数
  13. # 运行 upgrade_1220
  14. # 添加消费记录的组名字段
  15. def append_groupName_to_ConsumeRecord():
  16. for record in ConsumeRecord.objects():
  17. updated = record.update(groupName=Group.get_group(record.groupId).get('groupName'))
  18. assert updated, 'cannot update ConsumeRecord(%s)' % (record.id,)
  19. if __name__ == '__main__':
  20. print u'添加消费记录的组名字段'
  21. append_groupName_to_ConsumeRecord()