Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. class MyUserManager(BaseUserManager):
  2. def create_user(self, email,username,Nationality,Mother_language,Wish_language,Profile_image,status_message,password=None):
  3.  
  4. if not email:
  5. raise ValueError('Users must have an email address')
  6. if email.startswith("2"):
  7. raise ValueError('Users must have an email address')
  8.  
  9. user = self.model(
  10. email=self.normalize_email(email),
  11. username=username,
  12. Profile_image=Profile_image,
  13. Nationality=Nationality,
  14. Mother_language=Mother_language,
  15. Wish_language=Wish_language,
  16. status_message=status_message,
  17. )
  18.  
  19. user.set_password(password)
  20. user.save(using=self._db)
  21. return user
  22.  
  23. def create_superuser(self, email, username,Nationality,Mother_language,Wish_language,password,status_message,Profile_image):
  24.  
  25. user = self.create_user(email,
  26. password=password,
  27. username=username,
  28. Profile_image=Profile_image,
  29. Nationality=Nationality,
  30. Mother_language=Mother_language,
  31. Wish_language=Wish_language,
  32. status_message=status_message,
  33. )
  34. user.is_admin = True
  35. user.save(using=self._db)
  36. return user
  37.  
  38.  
  39. class MyUser(AbstractBaseUser):
  40. email = models.EmailField(
  41. verbose_name='Email',
  42. max_length=255,
  43. unique=True,null = False
  44. )
  45. username = models.CharField(max_length = 30, null = False)
  46.  
  47. Nationality =models.CharField(max_length = 30,choices= Country_choice,null = False )
  48. Mother_language = models.CharField(max_length = 30,choices= Language_list,null = False)
  49. Wish_language =models.CharField(max_length = 30,choices= Language_list,null = False)
  50. is_active = models.BooleanField(default=True)
  51. is_admin = models.BooleanField(default=False)
  52. Profile_image = models.ImageField(upload_to='profile_images',blank=True, default= 'profile_images/deafult-profile-image.png')
  53. status_message=models.CharField(max_length = 500,null = True)
  54. objects = MyUserManager()
  55.  
  56.  
  57.  
  58. USERNAME_FIELD = 'email'
  59. REQUIRED_FIELDS = ['username','Nationality','Mother_language','Wish_language','Profile_image','status_message']
  60.  
  61. import os
  62.  
  63. os.environ.setdefault('DJANGO_SETTINGS_MODULE',
  64. 'wadproject.settings')
  65.  
  66. import django
  67.  
  68. django.setup()
  69.  
  70. from LanguageExchange.models import MyUser
  71.  
  72.  
  73. def populate():
  74.  
  75.  
  76. MyUser = [{ "email": "11111@student.gla.ac.uk",
  77. "username": "Daivid",
  78. "password":"123456789",
  79. "Nationalityty": "Albania",
  80. "Mother_language": "Albanian",
  81. "Wish_language": "English",
  82. "Profile_image":"",
  83. "status_message":"Hello! I am david"
  84. },
  85.  
  86. {"email": "222221@student.gla.ac.uk",
  87. "password":"123456789",
  88. "username": "Daren",
  89. "Nationality": "Albania",
  90. "Mother_language": "Albanian",
  91. "Wish_language": "English",
  92. "Profile_image": "",
  93. "status_message":"Hello! I am daren"
  94. }
  95.  
  96. ]
  97.  
  98.  
  99.  
  100. def add_user(email, username,Nationality,Mother_language,Wish_language,password,status_message,Profile_image):
  101. M = MyUser.objects.get_or_create(email=email, username=username,Nationality=Nationality,Mother_language=Mother_language,Wish_language=Wish_language,password=password,status_message=status_message,Profile_image=Profile_image)[0]
  102. M.email=email
  103. M.username=username
  104. M.Nationality=Nationality
  105. M.Mother_language=Mother_language
  106. M.Wish_language=Wish_language
  107. M.password=password
  108. M.status_message=status_message
  109. M.Profile_image=Profile_image
  110. M.save()
  111. return M
  112.  
  113.  
  114.  
  115.  
  116. # Start execution here!
  117. if __name__ == '__main__':
  118. print("Starting Rango population script...")
  119. populate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement