def handle(self, *args, **options): print(join(settings.BASE_DIR, options['file'])) json_file = open(join(settings.BASE_DIR, options['file'])) dados = json.load(json_file) users = dados['users'] for u in users: u['address'].pop('geo') address = Address(**u['address']) address.save() #user = User() #user.username = u['username'] #user.email = u['email'] password = '******' user = User.objects.create_user(u['username'], u['email'], password) user.address = address user.save() profile = Profile() profile.user = user profile.address = address profile.save() posts = dados['posts'] for p in posts: post = Post() post.profile = Profile.objects.get(user=User.objects.get( id=p['userId'])) post.body = p.get('body') or 'sem corpo' post.title = p.get('title') or 'sem title' post.save() comments = dados['comments'] for c in comments: com = Comment() com.name = c['name'] com.email = c['email'] com.body = c['body'] com.post = Post.objects.get(pk=c['postId']) com.save()
address.save() user = User() user.username = u['username'] user.email = u['email'] user.password = '******' user.address = address user.save() profile = Profile() profile.user = user profile.address = address profile.save() posts = dados['posts'] for p in posts: post = Post() post.profile = Profile.objects.get(user=User.objects.get(id=p['userId'])) post.body = p.get('body') or 'sem corpo' post.title = p.get('title') or 'sem title' post.save() comments = dados['comments'] for c in comments: com = Comment() com.name = c['name'] com.email = c['email'] com.body = c['body'] com.post = Post.objects.get(pk=c['postId']) com.save()