-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* check if user is superuser
- Loading branch information
Showing
6 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dj_rest_auth import serializers as dj_serializers | ||
from django.contrib.auth import get_user_model | ||
|
||
# Get the UserModel | ||
UserModel = get_user_model() | ||
|
||
|
||
class UserDetailsSerializer(dj_serializers.UserDetailsSerializer): | ||
""" | ||
Custom User model w/o password | ||
""" | ||
|
||
class Meta: | ||
extra_fields = [] | ||
if hasattr(UserModel, "USERNAME_FIELD"): | ||
extra_fields.append(UserModel.USERNAME_FIELD) | ||
if hasattr(UserModel, "EMAIL_FIELD"): | ||
extra_fields.append(UserModel.EMAIL_FIELD) | ||
if hasattr(UserModel, "first_name"): | ||
extra_fields.append("first_name") | ||
if hasattr(UserModel, "last_name"): | ||
extra_fields.append("last_name") | ||
if hasattr(UserModel, "is_superuser"): | ||
extra_fields.append("is_superuser") | ||
model = UserModel | ||
fields = ("pk", *extra_fields) | ||
read_only_fields = ("email", "is_superuser") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters