Guest User

Untitled

a guest
Oct 9th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  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.  
  9. from django.db import models
  10. from django.contrib.auth import get_user_model
  11.  
  12. from django.utils.crypto import get_random_string
  13.  
  14. from faker import Faker
  15. fake = Faker()
  16.  
  17. from django.utils import timezone
  18. import pytz
  19.  
  20. number_of_users = 11
  21. username_length = 8
  22. default_password = '12345678'
  23.  
  24. for 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.  
  47. print("Done...")
Add Comment
Please, Sign In to add comment