Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
red_brick_board
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ciella Francisco
red_brick_board
Commits
da4ed91f
Commit
da4ed91f
authored
Mar 11, 2024
by
gab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created CustomUserManager for easier create super/user
parent
9a5b21af
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
models.py
redbrickboard/accounts/models.py
+24
-1
No files found.
redbrickboard/accounts/models.py
View file @
da4ed91f
from
django.db
import
models
from
django.contrib.auth.models
import
AbstractUser
from
django.contrib.auth.models
import
AbstractUser
,
UserManager
class
CustomUserManager
(
UserManager
):
def
create_user
(
self
,
email
,
password
,
**
extra_fields
):
if
not
email
:
raise
ValueError
(
'Email for user must be set.'
)
email
=
self
.
normalize_email
(
email
)
user
=
self
.
model
(
email
=
email
,
**
extra_fields
)
user
.
set_password
(
password
)
user
.
save
()
return
user
def
create_superuser
(
self
,
email
,
password
,
**
extra_fields
):
extra_fields
.
setdefault
(
'is_staff'
,
True
)
extra_fields
.
setdefault
(
'is_superuser'
,
True
)
if
extra_fields
.
get
(
'is_staff'
)
is
not
True
:
raise
ValueError
(
'Superuser must have is_staff=True.'
)
if
extra_fields
.
get
(
'is_superuser'
)
is
not
True
:
raise
ValueError
(
'Superuser must have is_superuser=True.'
)
return
self
.
create_user
(
email
,
password
,
**
extra_fields
)
# Create your models here.
class
CustomUser
(
AbstractUser
):
...
...
@@ -19,5 +40,7 @@ class CustomUser(AbstractUser):
USERNAME_FIELD
=
'email'
REQUIRED_FIELDS
=
[]
objects
=
CustomUserManager
()
def
__str__
(
self
):
return
self
.
first_name
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment