Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyUserManager(BaseUserManager):
- def create_user(self, email,username,Nationality,Mother_language,Wish_language,Profile_image,status_message,password=None):
- if not email:
- raise ValueError('Users must have an email address')
- if email.startswith("2"):
- raise ValueError('Users must have an email address')
- user = self.model(
- email=self.normalize_email(email),
- username=username,
- Profile_image=Profile_image,
- Nationality=Nationality,
- Mother_language=Mother_language,
- Wish_language=Wish_language,
- status_message=status_message,
- )
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_superuser(self, email, username,Nationality,Mother_language,Wish_language,password,status_message,Profile_image):
- user = self.create_user(email,
- password=password,
- username=username,
- Profile_image=Profile_image,
- Nationality=Nationality,
- Mother_language=Mother_language,
- Wish_language=Wish_language,
- status_message=status_message,
- )
- user.is_admin = True
- user.save(using=self._db)
- return user
- class MyUser(AbstractBaseUser):
- email = models.EmailField(
- verbose_name='Email',
- max_length=255,
- unique=True,null = False
- )
- username = models.CharField(max_length = 30, null = False)
- Nationality =models.CharField(max_length = 30,choices= Country_choice,null = False )
- Mother_language = models.CharField(max_length = 30,choices= Language_list,null = False)
- Wish_language =models.CharField(max_length = 30,choices= Language_list,null = False)
- is_active = models.BooleanField(default=True)
- is_admin = models.BooleanField(default=False)
- Profile_image = models.ImageField(upload_to='profile_images',blank=True, default= 'profile_images/deafult-profile-image.png')
- status_message=models.CharField(max_length = 500,null = True)
- objects = MyUserManager()
- USERNAME_FIELD = 'email'
- REQUIRED_FIELDS = ['username','Nationality','Mother_language','Wish_language','Profile_image','status_message']
- import os
- os.environ.setdefault('DJANGO_SETTINGS_MODULE',
- 'wadproject.settings')
- import django
- django.setup()
- from LanguageExchange.models import MyUser
- def populate():
- MyUser = [{ "email": "11111@student.gla.ac.uk",
- "username": "Daivid",
- "password":"123456789",
- "Nationalityty": "Albania",
- "Mother_language": "Albanian",
- "Wish_language": "English",
- "Profile_image":"",
- "status_message":"Hello! I am david"
- },
- {"email": "222221@student.gla.ac.uk",
- "password":"123456789",
- "username": "Daren",
- "Nationality": "Albania",
- "Mother_language": "Albanian",
- "Wish_language": "English",
- "Profile_image": "",
- "status_message":"Hello! I am daren"
- }
- ]
- def add_user(email, username,Nationality,Mother_language,Wish_language,password,status_message,Profile_image):
- 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]
- M.email=email
- M.username=username
- M.Nationality=Nationality
- M.Mother_language=Mother_language
- M.Wish_language=Wish_language
- M.password=password
- M.status_message=status_message
- M.Profile_image=Profile_image
- M.save()
- return M
- # Start execution here!
- if __name__ == '__main__':
- print("Starting Rango population script...")
- populate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement