Admin interface fixes

This commit is contained in:
Corban-Lee Jones 2024-03-13 17:22:37 +00:00
parent 0d9356000e
commit 9ea5a645a0
4 changed files with 46 additions and 7 deletions

View File

@ -2,12 +2,12 @@
import logging
from django.contrib.auth import models
from django.contrib.auth.models import BaseUserManager
log = logging.getLogger(__name__)
class DiscordUserOAuth2Manager(models.UserManager):
class DiscordUserOAuth2Manager(BaseUserManager):
"""
Manager for the DiscordUser class.
"""

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.1 on 2024-03-13 13:45
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('authentication', '0001_initial'),
]
operations = [
migrations.AlterModelManagers(
name='discorduser',
managers=[
],
),
]

View File

@ -3,6 +3,7 @@
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
# from django.contrib.auth.models import AbstractBaseUser
from .managers import DiscordUserOAuth2Manager
@ -12,7 +13,6 @@ class DiscordUser(models.Model):
Represents a User authenticated with Discord OAuth2.
"""
# Discord Attributes
id = models.PositiveBigIntegerField(
@ -88,12 +88,33 @@ class DiscordUser(models.Model):
objects = DiscordUserOAuth2Manager()
def is_authenticated(self, request):
return True
REQUIRED_FIELDS = []
USERNAME_FIELD = "username"
def __str__(self):
return self.global_name or self.username
@property
def avatar_url(self):
return f"https://cdn.discordapp.com/avatars/{self.id}/{self.avatar}.webp?size=128"
return f"https://cdn.discordapp.com/avatars/{self.id}/{self.avatar}.webp?size=128"
@property
def password(self):
return "password"
@property
def is_authenticated(self):
return True
@property
def is_anonymous(self):
return False
def get_username(self):
return self.username
def has_perm(self, perm, obj=None):
return self.is_superuser
def has_module_perms(self, app_label):
return self.is_superuser

View File

@ -58,7 +58,7 @@ LOGIN_URL = "/login/"
LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"
# AUTH_USER_MODEL = "authentication.User"
AUTH_USER_MODEL = "authentication.DiscordUser"
TEMPLATES = [
{