Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # file name: rh_add_fake_user.py
- # created: 2018-07-17
- # This script will add user programmatically
- # to run this script using local settings, just invoke
- # python manage.py shell < rh_add_fake_user.py --settings=myproject.settings.local
- from django.db import models
- from django.contrib.auth import get_user_model
- from django.utils.crypto import get_random_string
- from faker import Faker
- fake = Faker()
- from django.utils import timezone
- import pytz
- number_of_users = 11
- username_length = 8
- default_password = '12345678'
- for num in range(1, number_of_users):
- random_string = get_random_string(length=username_length)
- User = get_user_model()
- user_email = str(random_string) + '@gmail.com'
- user_password = default_password
- user = User.objects.create_user(user_email, password=user_password)
- user.is_superuser=False
- user.is_staff=False
- user.is_vendor=True
- user.is_active=True
- user.first_name=fake.first_name()
- user.last_name=fake.last_name()
- user.date_joined = timezone.now()
- user.save()
- print(str(num) + " User with email " + user_email + " created.")
- print("Done...")
Add Comment
Please, Sign In to add comment