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()