fork download
  1. from django.core.management.base import BaseCommand, CommandError
  2. from Registry.models import OdeskProfileData
  3. import json
  4. class Command(BaseCommand):
  5. args = 'json.data'
  6. help = 'Fill models with data from json'
  7.  
  8. def handle(self, *args, **options):
  9. with open(*args) as data_file:
  10. data = json.load(data_file)
  11. Odesk = OdeskProfileData()
  12. i = 0
  13. try:
  14. for items in data:
  15. Odesk.title = data[i]['title']
  16. Odesk.skills = data[i]['skills']
  17. Odesk.country = data[i]['country']
  18. Odesk.profile_id = data[i]['id']
  19. except OdeskProfileData.DoesNotExist:
  20. raise CommandError('No items')
  21. Odesk.save()
  22. i += 1
Runtime error #stdin #stdout #stderr 0.02s 8688KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'django'