Skip to content

Commit 1136e83

Browse files
committed
updates
1 parent bca951b commit 1136e83

32 files changed

+355
-272
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Michael Herman
3+
Copyright (c) 2023 TestDriven.io
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Check out the [post](https://testdriven.io/blog/django-custom-user-model/).
1717

1818
```sh
1919
$ python3 -m venv env && source env/bin/activate
20-
(env)$ pip install Django==3.2.2
20+
(env)$ pip install Django
2121
(env)$ python manage.py makemigrations
2222
(env)$ python manage.py migrate
2323
(env)$ python manage.py runserver

abstract-base-user-example/hello_django/asgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
It exposes the ASGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
88
"""
99

1010
import os
1111

1212
from django.core.asgi import get_asgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hello_django.settings')
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello_django.settings")
1515

1616
application = get_asgi_application()
Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
Django settings for hello_django project.
33
4-
Generated by 'django-admin startproject' using Django 3.2.2.
4+
Generated by 'django-admin startproject' using Django 4.1.5.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/topics/settings/
7+
https://docs.djangoproject.com/en/4.1/topics/settings/
88
99
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/3.2/ref/settings/
10+
https://docs.djangoproject.com/en/4.1/ref/settings/
1111
"""
1212

1313
from pathlib import Path
@@ -17,10 +17,10 @@
1717

1818

1919
# Quick-start development settings - unsuitable for production
20-
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
20+
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
2121

2222
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'django-insecure-hc2q!paugx$0f0z05&3*9co36qj-o(!!fk=ymz4%5d2drk_jpd'
23+
SECRET_KEY = "django-insecure-#h8#5yy)jsc@sa+r(1t@f^$)(fs(36&q@8l^+&6=c^0r)jk&)4"
2424

2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
@@ -31,103 +31,102 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34-
'django.contrib.admin',
35-
'django.contrib.auth',
36-
'django.contrib.contenttypes',
37-
'django.contrib.sessions',
38-
'django.contrib.messages',
39-
'django.contrib.staticfiles',
40-
41-
'users',
34+
"django.contrib.admin",
35+
"django.contrib.auth",
36+
"django.contrib.contenttypes",
37+
"django.contrib.sessions",
38+
"django.contrib.messages",
39+
"django.contrib.staticfiles",
40+
41+
"users", # new
4242
]
4343

4444
MIDDLEWARE = [
45-
'django.middleware.security.SecurityMiddleware',
46-
'django.contrib.sessions.middleware.SessionMiddleware',
47-
'django.middleware.common.CommonMiddleware',
48-
'django.middleware.csrf.CsrfViewMiddleware',
49-
'django.contrib.auth.middleware.AuthenticationMiddleware',
50-
'django.contrib.messages.middleware.MessageMiddleware',
51-
'django.middleware.clickjacking.XFrameOptionsMiddleware',
45+
"django.middleware.security.SecurityMiddleware",
46+
"django.contrib.sessions.middleware.SessionMiddleware",
47+
"django.middleware.common.CommonMiddleware",
48+
"django.middleware.csrf.CsrfViewMiddleware",
49+
"django.contrib.auth.middleware.AuthenticationMiddleware",
50+
"django.contrib.messages.middleware.MessageMiddleware",
51+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5252
]
5353

54-
ROOT_URLCONF = 'hello_django.urls'
54+
ROOT_URLCONF = "hello_django.urls"
5555

5656
TEMPLATES = [
5757
{
58-
'BACKEND': 'django.template.backends.django.DjangoTemplates',
59-
'DIRS': [
60-
BASE_DIR / 'templates',
58+
"BACKEND": "django.template.backends.django.DjangoTemplates",
59+
"DIRS": [
60+
BASE_DIR / "templates",
6161
],
62-
'APP_DIRS': True,
63-
'OPTIONS': {
64-
'context_processors': [
65-
'django.template.context_processors.debug',
66-
'django.template.context_processors.request',
67-
'django.contrib.auth.context_processors.auth',
68-
'django.contrib.messages.context_processors.messages',
62+
"APP_DIRS": True,
63+
"OPTIONS": {
64+
"context_processors": [
65+
"django.template.context_processors.debug",
66+
"django.template.context_processors.request",
67+
"django.contrib.auth.context_processors.auth",
68+
"django.contrib.messages.context_processors.messages",
6969
],
7070
},
7171
},
7272
]
7373

74-
WSGI_APPLICATION = 'hello_django.wsgi.application'
74+
WSGI_APPLICATION = "hello_django.wsgi.application"
7575

7676

7777
# Database
78-
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
78+
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
7979

8080
DATABASES = {
81-
'default': {
82-
'ENGINE': 'django.db.backends.sqlite3',
83-
'NAME': BASE_DIR / 'db.sqlite3',
81+
"default": {
82+
"ENGINE": "django.db.backends.sqlite3",
83+
"NAME": BASE_DIR / "db.sqlite3",
8484
}
8585
}
8686

8787

8888
# Password validation
89-
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
89+
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
9090

9191
AUTH_PASSWORD_VALIDATORS = [
9292
{
93-
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
9494
},
9595
{
96-
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
9797
},
9898
{
99-
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
100100
},
101101
{
102-
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
103103
},
104104
]
105105

106106

107107
# Internationalization
108-
# https://docs.djangoproject.com/en/3.2/topics/i18n/
108+
# https://docs.djangoproject.com/en/4.1/topics/i18n/
109109

110-
LANGUAGE_CODE = 'en-us'
110+
LANGUAGE_CODE = "en-us"
111111

112-
TIME_ZONE = 'UTC'
112+
TIME_ZONE = "UTC"
113113

114114
USE_I18N = True
115115

116-
USE_L10N = True
117-
118116
USE_TZ = True
119117

120118

121119
# Static files (CSS, JavaScript, Images)
122-
# https://docs.djangoproject.com/en/3.2/howto/static-files/
120+
# https://docs.djangoproject.com/en/4.1/howto/static-files/
123121

124-
STATIC_URL = '/static/'
122+
STATIC_URL = "static/"
125123

126124
# Default primary key field type
127-
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
125+
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
126+
127+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
128128

129-
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
129+
AUTH_USER_MODEL = "users.CustomUser"
130130

131-
AUTH_USER_MODEL = 'users.CustomUser'
132-
LOGIN_REDIRECT_URL = 'home'
133-
LOGOUT_REDIRECT_URL = 'home'
131+
LOGIN_REDIRECT_URL = "home"
132+
LOGOUT_REDIRECT_URL = "home"

abstract-base-user-example/hello_django/urls.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from django.urls import path, include
33
from django.views.generic.base import TemplateView
44

5-
65
urlpatterns = [
7-
path('', TemplateView.as_view(template_name='home.html'), name='home'),
8-
path('admin/', admin.site.urls),
9-
path('users/', include('users.urls')),
10-
path('users/', include('django.contrib.auth.urls')),
6+
path("", TemplateView.as_view(template_name="home.html"), name="home"),
7+
path("admin/", admin.site.urls),
8+
path("users/", include("users.urls")),
9+
path("users/", include("django.contrib.auth.urls")),
1110
]

abstract-base-user-example/hello_django/wsgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
It exposes the WSGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/wsgi/
88
"""
99

1010
import os
1111

1212
from django.core.wsgi import get_wsgi_application
1313

14-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hello_django.settings')
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello_django.settings")
1515

1616
application = get_wsgi_application()

abstract-base-user-example/manage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def main():
88
"""Run administrative tasks."""
9-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hello_django.settings')
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hello_django.settings")
1010
try:
1111
from django.core.management import execute_from_command_line
1212
except ImportError as exc:
@@ -18,5 +18,5 @@ def main():
1818
execute_from_command_line(sys.argv)
1919

2020

21-
if __name__ == '__main__':
21+
if __name__ == "__main__":
2222
main()

abstract-base-user-example/users/admin.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ class CustomUserAdmin(UserAdmin):
99
add_form = CustomUserCreationForm
1010
form = CustomUserChangeForm
1111
model = CustomUser
12-
list_display = ('email', 'is_staff', 'is_active',)
13-
list_filter = ('email', 'is_staff', 'is_active',)
12+
list_display = ("email", "is_staff", "is_active",)
13+
list_filter = ("email", "is_staff", "is_active",)
1414
fieldsets = (
15-
(None, {'fields': ('email', 'password')}),
16-
('Permissions', {'fields': ('is_staff', 'is_active')}),
15+
(None, {"fields": ("email", "password")}),
16+
("Permissions", {"fields": ("is_staff", "is_active", "groups", "user_permissions")}),
1717
)
1818
add_fieldsets = (
1919
(None, {
20-
'classes': ('wide',),
21-
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active')}
20+
"classes": ("wide",),
21+
"fields": (
22+
"email", "password1", "password2", "is_staff",
23+
"is_active", "groups", "user_permissions"
24+
)}
2225
),
2326
)
24-
search_fields = ('email',)
25-
ordering = ('email',)
27+
search_fields = ("email",)
28+
ordering = ("email",)
2629

2730

2831
admin.site.register(CustomUser, CustomUserAdmin)

abstract-base-user-example/users/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class UsersConfig(AppConfig):
5-
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'users'
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "users"

abstract-base-user-example/users/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ class CustomUserCreationForm(UserCreationForm):
77

88
class Meta:
99
model = CustomUser
10-
fields = ('email',)
10+
fields = ("email",)
1111

1212

1313
class CustomUserChangeForm(UserChangeForm):
1414

1515
class Meta:
1616
model = CustomUser
17-
fields = ('email',)
17+
fields = ("email",)

0 commit comments

Comments
 (0)