Skip to content

Instantly share code, notes, and snippets.

View BrockHerion's full-sized avatar
🏠
Working from home

Brock Herion BrockHerion

🏠
Working from home
View GitHub Profile
@BrockHerion
BrockHerion / serializers.py
Last active August 27, 2020 00:59
User Registration Serializer
from .models import User
class UserRegistrationSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = (
'email',
'password'
)
@BrockHerion
BrockHerion / settings.py
Created August 27, 2020 00:22
Settings for DjangoRest and JWT
# Other settings not shown
# Set your auth user to the new user you have created
AUTH_USER_MODEL = 'api.User'
# We need to add our api app and the rest framework to INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
@BrockHerion
BrockHerion / manager.py
Created August 27, 2020 00:11
Create a custom user manager
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import ugettext_lazy as _
class CustomUserManager(BaseUserManager):
"""
Custom user model where the email address is the unique identifier
and has an is_admin field to allow access to the admin app
"""
def create_user(self, email, password, **extra_fields):
@BrockHerion
BrockHerion / models.py
Last active November 5, 2020 04:32
Create user fields in models.py
import uuid
from django.db import models
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils import timezone
from .managers import CustomUserManager
# Create your models here.
@BrockHerion
BrockHerion / models.py
Created August 26, 2020 19:49
Create roles to use in our application
import uuid
from django.db import models
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils import timezone
from .managers import CustomUserManager
# Create your models here.