custom user model that maintains id as pk
This commit is contained in:
@@ -2,4 +2,4 @@ from django.apps import AppConfig
|
||||
|
||||
|
||||
class LyricConfig(AppConfig):
|
||||
name = 'lyric'
|
||||
name = 'apps.lyric'
|
||||
|
||||
21
src/apps/lyric/migrations/0001_initial.py
Normal file
21
src/apps/lyric/migrations/0001_initial.py
Normal 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)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -1,3 +1,10 @@
|
||||
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
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
0
src/apps/lyric/tests/__init__.py
Normal file
0
src/apps/lyric/tests/__init__.py
Normal file
15
src/apps/lyric/tests/test_models.py
Normal file
15
src/apps/lyric/tests/test_models.py
Normal 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")
|
||||
@@ -47,6 +47,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.staticfiles',
|
||||
# Custom apps
|
||||
'apps.dashboard',
|
||||
'apps.lyric',
|
||||
# Depend apps
|
||||
]
|
||||
|
||||
@@ -110,6 +111,8 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
},
|
||||
]
|
||||
|
||||
AUTH_USER_MODEL = "lyric.User"
|
||||
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
||||
|
||||
Reference in New Issue
Block a user