Use Python Faker to create users automatically

from django.contrib.auth.models import User
from faker import Faker
fake = Faker()

for i in range(0,200):
    name = fake.name()
    first_name = name.split(' ')[0]
    last_name = ' '.join(name.split(' ')[-1:])
    username = first_name[0].lower() + last_name.lower().replace(' ', '')
    user = User.objects.create_user(username, password=username)
    user.first_name = first_name
    user.last_name = last_name
    user.is_superuser = False
    user.is_staff = False
    user.email = username + "@" + last_name.lower() + ".com"
    user.save()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.