class Command(BaseCommand): def handle(self, *args, **options): with open('user.json', 'a', encoding='utf-8') as f: f.write(json.dumps({'name': name, 'phone': phone, 'sex': sex_code[sex], 'birthday': birthday, 'profession': profession_code[profession], 'region': region.code, 'corporation_type': corporation_code[corporation_type], 'corporation': corporation, 'title': title_code[title] }, ensure_ascii=False) + '\n')