fi
This commit is contained in:
28
core/apps/accounts/management/commands/import_users.py
Normal file
28
core/apps/accounts/management/commands/import_users.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import json
|
||||
|
||||
from django.core.management import BaseCommand
|
||||
|
||||
from core.apps.accounts.models import User
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('file_path', type=str)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
file_path = options['file_path']
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
data = json.load(f)
|
||||
|
||||
for item in data['data']['data']:
|
||||
User.objects.get_or_create(
|
||||
username=item['login'],
|
||||
defaults={
|
||||
'full_name': item['full_name'],
|
||||
'phone_number': item['phone'],
|
||||
'password': '12345678a0'
|
||||
}
|
||||
)
|
||||
|
||||
self.stdout.write("Users added")
|
||||
Reference in New Issue
Block a user