-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from weaverse-techtide/dev
10월 13일
- Loading branch information
Showing
77 changed files
with
5,911 additions
and
886 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ jobs: | |
python manage.py migrate | ||
- name: 테스트 실행 | ||
run: | | ||
python manage.py test | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,97 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin | ||
|
||
from .models import CustomUser | ||
|
||
admin.site.register(CustomUser) | ||
|
||
@admin.register(CustomUser) | ||
class CustomUserAdmin(UserAdmin): | ||
""" | ||
관리자로 하여금 커스텀 사용자 모델을 관리하기 위해 제공되는 관리자 클래스입니다. | ||
- 모델로 CustomUser를 사용합니다. | ||
- 커스텀 사용자 수정 및 생성 폼을 제공합니다. | ||
- 커스텀 사용자 목록을 조회할 수 있으며, 필터링 및 검색 옵션을 제공합니다. | ||
- 커스텀 사용자 목록에 표시될 필드들과 정렬 기준을 제공합니다. | ||
- 모든 유형의 커스텀 사용자을 생성하는 기능을 제공합니다. | ||
""" | ||
|
||
model = CustomUser | ||
|
||
readonly_fields = ("created_at", "updated_at") | ||
|
||
fieldsets = ( | ||
("Login info", {"fields": ("email", "nickname", "password")}), | ||
("Personal info", {"fields": ("first_name", "last_name", "introduction")}), | ||
( | ||
"Permissions", | ||
{ | ||
"fields": ( | ||
"is_active", | ||
"is_staff", | ||
"is_superuser", | ||
"groups", | ||
"user_permissions", | ||
), | ||
"classes": ("wide",), | ||
}, | ||
), | ||
( | ||
"Important dates", | ||
{ | ||
"fields": ("last_login", "created_at", "updated_at"), | ||
"classes": ("wide",), | ||
}, | ||
), | ||
) | ||
|
||
add_fieldsets = ( | ||
( | ||
"Register info", | ||
{ | ||
"fields": ( | ||
"email", | ||
"nickname", | ||
"password1", | ||
"password2", | ||
"is_staff", | ||
"is_superuser", | ||
), | ||
}, | ||
), | ||
) | ||
|
||
list_display = ("email", "nickname", "is_staff", "is_superuser") | ||
list_filter = ("is_staff", "is_superuser", "is_active") | ||
search_fields = ("email", "nickname", "first_name", "last_name") | ||
ordering = ("email", "created_at") | ||
|
||
def save_model(self, request, obj, form, change): | ||
if not change: | ||
if form.cleaned_data.get("is_staff") and not form.cleaned_data.get( | ||
"is_superuser" | ||
): | ||
CustomUser.objects.create_staff( | ||
email=form.cleaned_data["email"], | ||
password=form.cleaned_data["password1"], | ||
nickname=form.cleaned_data["nickname"], | ||
) | ||
elif form.cleaned_data.get("is_superuser"): | ||
CustomUser.objects.create_superuser( | ||
email=form.cleaned_data["email"], | ||
password=form.cleaned_data["password1"], | ||
nickname=form.cleaned_data["nickname"], | ||
) | ||
else: | ||
CustomUser.objects.create_user( | ||
email=form.cleaned_data["email"], | ||
password=form.cleaned_data["password1"], | ||
nickname=form.cleaned_data["nickname"], | ||
) | ||
else: | ||
obj.email = form.cleaned_data.get("email", obj.email) | ||
obj.nickname = form.cleaned_data.get("nickname", obj.nickname) | ||
if "password1" in form.cleaned_data: | ||
obj.set_password(form.cleaned_data["password1"]) | ||
obj.is_staff = form.cleaned_data.get("is_staff", obj.is_staff) | ||
obj.is_superuser = form.cleaned_data.get("is_superuser", obj.is_superuser) | ||
obj.save() |
32 changes: 32 additions & 0 deletions
32
accounts/migrations/0004_remove_customuser_date_joined_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Generated by Django 5.1.1 on 2024-10-04 06:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0003_customuser_created_at_customuser_introduction_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='customuser', | ||
name='date_joined', | ||
), | ||
migrations.AlterField( | ||
model_name='customuser', | ||
name='introduction', | ||
field=models.TextField(blank=True, max_length=20, null=True, verbose_name='자기소개'), | ||
), | ||
migrations.AlterField( | ||
model_name='customuser', | ||
name='nickname', | ||
field=models.CharField(max_length=20, unique=True, verbose_name='닉네임'), | ||
), | ||
migrations.AlterField( | ||
model_name='customuser', | ||
name='phone_number', | ||
field=models.CharField(blank=True, max_length=20, null=True, verbose_name='연락처'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.1.1 on 2024-10-10 06:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0004_remove_customuser_date_joined_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='customuser', | ||
name='profile_image', | ||
field=models.ImageField(blank=True, default='profile_images/default.jpg', upload_to='profile_images/'), | ||
), | ||
] |
17 changes: 17 additions & 0 deletions
17
accounts/migrations/0006_remove_customuser_profile_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 5.1.1 on 2024-10-10 07:31 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0005_customuser_profile_image'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='customuser', | ||
name='profile_image', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.