from django.core.management.base import BaseCommand, CommandError
from Registry.models import OdeskProfileData
import json
class Command(BaseCommand):
args = 'json.data'
help = 'Fill models with data from json'
def handle(self, *args, **options):
with open(*args) as data_file:
data = json.load(data_file)
Odesk = OdeskProfileData()
i = 0
try:
for items in data:
Odesk.title = data[i]['title']
Odesk.skills = data[i]['skills']
Odesk.country = data[i]['country']
Odesk.profile_id = data[i]['id']
except OdeskProfileData.DoesNotExist:
raise CommandError('No items')
Odesk.save()
i += 1
ZnJvbSBkamFuZ28uY29yZS5tYW5hZ2VtZW50LmJhc2UgaW1wb3J0IEJhc2VDb21tYW5kLCBDb21tYW5kRXJyb3IKZnJvbSBSZWdpc3RyeS5tb2RlbHMgaW1wb3J0IE9kZXNrUHJvZmlsZURhdGEKaW1wb3J0IGpzb24KY2xhc3MgQ29tbWFuZChCYXNlQ29tbWFuZCk6CiAgICBhcmdzID0gJ2pzb24uZGF0YScKICAgIGhlbHAgPSAnRmlsbCBtb2RlbHMgd2l0aCBkYXRhIGZyb20ganNvbicKCiAgICBkZWYgaGFuZGxlKHNlbGYsICphcmdzLCAqKm9wdGlvbnMpOgogICAgICAgIHdpdGggb3BlbigqYXJncykgYXMgZGF0YV9maWxlOgogICAgICAgICAgICBkYXRhID0ganNvbi5sb2FkKGRhdGFfZmlsZSkKICAgICAgICBPZGVzayA9IE9kZXNrUHJvZmlsZURhdGEoKQogICAgICAgIGkgPSAwCiAgICAgICAgdHJ5OgogICAgICAgICAgICBmb3IgaXRlbXMgaW4gZGF0YToKICAgICAgICAgICAgICAgIE9kZXNrLnRpdGxlID0gZGF0YVtpXVsndGl0bGUnXQogICAgICAgICAgICAgICAgT2Rlc2suc2tpbGxzID0gZGF0YVtpXVsnc2tpbGxzJ10KICAgICAgICAgICAgICAgIE9kZXNrLmNvdW50cnkgPSBkYXRhW2ldWydjb3VudHJ5J10KICAgICAgICAgICAgICAgIE9kZXNrLnByb2ZpbGVfaWQgPSBkYXRhW2ldWydpZCddCiAgICAgICAgZXhjZXB0IE9kZXNrUHJvZmlsZURhdGEuRG9lc05vdEV4aXN0OgogICAgICAgICAgICByYWlzZSBDb21tYW5kRXJyb3IoJ05vIGl0ZW1zJykKICAgICAgICBPZGVzay5zYXZlKCkKICAgICAgICBpICs9IDE=