Guest User

Untitled

a guest
Aug 3rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. class AccountManager(models.Manager):
  2. def create_with_user(user_kwargs=None, **kwargs):
  3. """
  4. Creates an Account and User, making the User an admin for that Account.
  5. Returns the newly created Account and User in a tuple.
  6.  
  7. """
  8.  
  9. account = super(AccountManager, self).create(**kwargs)
  10.  
  11. password = user_kwargs.pop('password')
  12. user_kwargs['account'] = account
  13.  
  14. user = User(**user_kwargs)
  15. user.set_password(user_password)
  16. user.save()
  17.  
  18. admins = account.groups.get(name=ADMINS_GROUP_NAME)
  19. users = account.groups.get(name=USERS_GROUP_NAME)
  20. user.groups.add(admins)
  21. user.groups.add(users)
  22.  
  23. return account, user
Add Comment
Please, Sign In to add comment