Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Openlobby Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
openlobby
Openlobby Server
Commits
24287f07
Commit
24287f07
authored
6 years ago
by
jan.bednarik
Browse files
Options
Downloads
Patches
Plain Diff
Fix User objects manager so createsuperuser works
parent
6ab3c47d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
openlobby/core/models.py
+6
-5
6 additions, 5 deletions
openlobby/core/models.py
with
6 additions
and
5 deletions
openlobby/core/models.py
+
6
−
5
View file @
24287f07
import
time
from
django.conf
import
settings
from
django.contrib.auth.base_user
import
BaseUserManager
from
django.contrib.auth.models
import
AbstractUser
from
django.contrib.auth.models
import
AbstractUser
,
UserManager
from
django.contrib.postgres.fields
import
JSONField
from
django.db
import
models
from
django.db.models
import
Count
...
...
@@ -10,7 +9,7 @@ from django.db.models import Q
from
django.utils
import
timezone
class
UserManager
(
Base
UserManager
):
class
Custom
UserManager
(
UserManager
):
def
sorted
(
self
,
**
kwargs
):
# inline import intentionally
from
openlobby.core.api.schema
import
(
...
...
@@ -22,6 +21,7 @@ class UserManager(BaseUserManager):
total_reports
=
Count
(
"
report
"
,
filter
=
Q
(
report__is_draft
=
False
))
)
sort_field
=
kwargs
.
get
(
"
sort
"
,
AUTHOR_SORT_LAST_NAME_ID
)
if
sort_field
==
AUTHOR_SORT_LAST_NAME_ID
:
return
qs
.
order_by
(
"
{}last_name
"
.
format
(
"
-
"
if
kwargs
.
get
(
"
reversed
"
,
False
)
else
""
),
...
...
@@ -32,7 +32,8 @@ class UserManager(BaseUserManager):
"
{}total_reports
"
.
format
(
""
if
kwargs
.
get
(
"
reversed
"
,
False
)
else
"
-
"
),
"
last_name
"
,
)
raise
NotImplemented
(
"
Other sort types are not implemented
"
)
raise
NotImplementedError
(
"
Other sort types are not implemented
"
)
class
User
(
AbstractUser
):
...
...
@@ -44,7 +45,7 @@ class User(AbstractUser):
extra
=
JSONField
(
null
=
True
,
blank
=
True
)
is_author
=
models
.
BooleanField
(
default
=
False
)
has_colliding_name
=
models
.
BooleanField
(
default
=
False
)
objects
=
UserManager
()
objects
=
Custom
UserManager
()
def
save
(
self
,
*
args
,
**
kwargs
):
# deal with first name and last name collisions
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment