def handle(self, *args, **kwargs): total = kwargs['total'] for i in range(total): user = RandomUser() User.objects.create_user(username=RandomUser.get_username(user), first_name=RandomUser.get_first_name(user), last_name=RandomUser.get_last_name(user), email=RandomUser.get_email(user), password=RandomUser.get_password(user), date_joined=RandomUser.get_registered(user))
def get_user_columns(id): cols = [] user = RandomUser() cols.append(id) cols.append(user.get_first_name()) cols.append(user.get_last_name()) cols.append('{} {}, {} {}'.format(user.get_street(), user.get_city(), user.get_state(), str(user.get_zipcode()))) cols.append(user.get_email()) cols.append(user.get_password()) return cols
import json import random from randomuser import RandomUser config = json.load(open('config.json')) api = lambda url: f'http://localhost:8000/api/{url}' user_count = 0 users = [] posts = [] while user_count != config['number_of_users']: user = RandomUser() user_data = { 'username': user.get_username(), 'password': user.get_password(), 'email': user.get_email(), 'first_name': user.get_first_name(), 'last_name': user.get_last_name() } resp = requests.post(api('users/'), json=user_data) if resp.status_code == 201: user_count += 1 user_data['id'] = resp.json().get('id') else: continue print('USER CREATED') token_data = {'username': user_data['username'], 'password': user_data['password']} resp = requests.post(api('token/'), json=token_data) if resp.status_code == 200: user_data['access'] = resp.json().get('access')