· 7 years ago · Oct 09, 2018, 08:54 AM
1# file name: rh_add_fake_user.py
2# created: 2018-07-17
3
4# This script will add user programmatically
5
6# to run this script using local settings, just invoke
7# python manage.py shell < rh_add_fake_user.py --settings=myproject.settings.local
8
9from django.db import models
10from django.contrib.auth import get_user_model
11
12from django.utils.crypto import get_random_string
13
14from faker import Faker
15fake = Faker()
16
17from django.utils import timezone
18import pytz
19
20number_of_users = 11
21username_length = 8
22default_password = '12345678'
23
24for num in range(1, number_of_users):
25 random_string = get_random_string(length=username_length)
26
27 User = get_user_model()
28
29 user_email = str(random_string) + '@gmail.com'
30 user_password = default_password
31
32 user = User.objects.create_user(user_email, password=user_password)
33 user.is_superuser=False
34 user.is_staff=False
35 user.is_vendor=True
36 user.is_active=True
37
38 user.first_name=fake.first_name()
39 user.last_name=fake.last_name()
40
41 user.date_joined = timezone.now()
42
43 user.save()
44
45 print(str(num) + " User with email " + user_email + " created.")
46
47print("Done...")