Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 | 6 |
from django.contrib.auth.base_user import BaseUserManager |
2 |
|
|
3 |
|
|
4 | 6 |
class UserManager(BaseUserManager): |
5 | 6 |
use_in_migrations = True |
6 |
|
|
7 | 6 |
def _create_user(self, email, password, **extra_fields): |
8 |
"""
|
|
9 |
Creates and saves a User with the given email and password.
|
|
10 |
"""
|
|
11 |
if not email: |
|
12 |
raise ValueError('The given email must be set') |
|
13 |
email = self.normalize_email(email) |
|
14 |
user = self.model(email=email, **extra_fields) |
|
15 |
user.set_password(password) |
|
16 |
user.save(using=self._db) |
|
17 |
return user |
|
18 |
|
|
19 | 6 |
def create_user(self, email, password=None, **extra_fields): |
20 |
extra_fields.setdefault('is_superuser', False) |
|
21 |
return self._create_user(email, password, **extra_fields) |
|
22 |
|
|
23 | 6 |
def create_superuser(self, email, password, **extra_fields): |
24 |
extra_fields.setdefault('is_superuser', True) |
|
25 |
|
|
26 |
if extra_fields.get('is_superuser') is not True: |
|
27 |
raise ValueError('Superuser must have is_superuser=True.') |
|
28 |
|
|
29 |
return self._create_user(email, password, **extra_fields) |
Read our documentation on viewing source code .