From 007a0d9d51b05d7255314292ca8b129c5bac00cc Mon Sep 17 00:00:00 2001 From: goddessana Date: Tue, 3 Oct 2023 22:15:24 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20accounts/admin=20=EC=97=90=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=ED=9E=8C=ED=8A=B8=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?#92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/accounts/admin.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/accounts/admin.py b/apps/accounts/admin.py index f492d92..47c9dc0 100644 --- a/apps/accounts/admin.py +++ b/apps/accounts/admin.py @@ -6,6 +6,7 @@ from django.contrib.auth.forms import ReadOnlyPasswordHashField from django.contrib.auth.models import Group from django.core.exceptions import ValidationError +from django.db.models import QuerySet from rest_framework.authtoken.models import TokenProxy from apps.accounts.models import User @@ -26,15 +27,16 @@ class Meta: "email", ] - def clean_password2(self): - password1 = self.cleaned_data.get("password1") - password2 = self.cleaned_data.get("password2") + def clean_password2(self) -> str | None: + password1: str | None = self.cleaned_data.get("password1") + password2: str | None = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise ValidationError("Passwords don't match") return password2 - def save(self, commit=True): + def save(self, commit: bool = True) -> User: user = super().save(commit=False) + assert isinstance(user, User) user.set_password(self.cleaned_data["password1"]) if commit: user.save() @@ -92,7 +94,8 @@ class UserAdmin(BaseUserAdmin): ordering = ["email"] @staticmethod - def social_accounts(obj): + def social_accounts(obj: User) -> str | QuerySet[User]: + assert hasattr(obj, "socialaccount_set") return ( obj.socialaccount_set.all() if obj.socialaccount_set.all()