add_org_data.py 744 B

12345678910111213141516171819202122232425
  1. import os
  2. import sys
  3. import time
  4. import django
  5. import json
  6. local_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. print(local_path)
  8. if local_path not in sys.path:
  9. sys.path.append(local_path)
  10. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kedong.settings")
  11. django.setup()
  12. from django.conf import settings
  13. from smartfarming.models.device import MongoDeviceType
  14. from smartfarming.models.user import UserPurview
  15. with open(os.path.join(local_path, "scripts/test/sa_device_type.json") , 'r', encoding='utf-8') as f:
  16. sa_device_type = json.load(f)
  17. for row in sa_device_type.get("rows"):
  18. MongoDeviceType.objects.get_or_create(
  19. id=row.get("id"),
  20. defaults=row
  21. )