upgrade_20180425.py 706 B

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. """
  4. Goal:
  5. put agentId to every adRecords
  6. """
  7. import os
  8. import sys
  9. #: current_dir - 2
  10. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  11. sys.path.insert(0, PROJECT_ROOT)
  12. from script.base import init_env, get_logger
  13. init_env(interactive=True)
  14. from apps.web.ad.models import AdRecord
  15. from apps.web.dealer.models import Dealer
  16. for record in AdRecord.objects():
  17. if record.dealerId:
  18. updated = record.update(agentId = Dealer.objects(id=str(record.dealerId)).get().agentId)
  19. assert updated, 'update failed, record id=%s' % (record.id,)
  20. print 'finished'