custom user model that maintains id as pk

This commit is contained in:
Disco DeDisco
2026-01-30 15:04:47 -05:00
parent a734901b80
commit d724e03c3c
7 changed files with 48 additions and 5 deletions

View File

@@ -2,4 +2,4 @@ from django.apps import AppConfig
class LyricConfig(AppConfig): class LyricConfig(AppConfig):
name = 'lyric' name = 'apps.lyric'

View File

@@ -0,0 +1,21 @@
# Generated by Django 6.0 on 2026-01-30 20:02
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254, unique=True)),
],
),
]

View File

@@ -1,3 +1,10 @@
from django.db import models from django.db import models
# Create your models here. class User(models.Model):
# email = models.EmailField(primary_key=True)
email = models.EmailField(unique=True)
REQUIRED_FIELDS = []
USERNAME_FIELD = "email"
is_anonymous = False
is_authenticated = True

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

View File

@@ -0,0 +1,15 @@
from django.contrib import auth
from django.test import TestCase
from ..models import User
class UserModelTest(TestCase):
def test_model_is_configured_for_django_auth(self):
self.assertEqual(auth.get_user_model(), User)
def test_user_is_valid_with_email_only(self):
user = User(email="a@b.cde")
user.full_clean() # should not raise
def test_id_is_primary_key(self):
user = User(id="123")
self.assertEqual(user.pk, "123")

View File

@@ -47,6 +47,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles', 'django.contrib.staticfiles',
# Custom apps # Custom apps
'apps.dashboard', 'apps.dashboard',
'apps.lyric',
# Depend apps # Depend apps
] ]
@@ -110,6 +111,8 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
AUTH_USER_MODEL = "lyric.User"
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/6.0/topics/i18n/ # https://docs.djangoproject.com/en/6.0/topics/i18n/