1+ from functools import partial
2+
13from django .contrib .auth .models import AbstractUser
24from django .contrib .contenttypes .fields import GenericRelation
35from django .core .exceptions import ValidationError
6+ from django .core .validators import URLValidator
47from django .db import models
58from django .db .models import QuerySet
69from django .utils import timezone
@@ -60,9 +63,18 @@ class CustomUser(AbstractUser):
6063 INVESTOR = constants .INVESTOR
6164
6265 username = None
63- email = models .EmailField (unique = True )
64- first_name = models .CharField (max_length = 255 , validators = [user_name_validator ])
65- last_name = models .CharField (max_length = 255 , validators = [user_name_validator ])
66+ email = models .EmailField (
67+ unique = True ,
68+ error_messages = {
69+ "unique" : "Пользователь с таким email уже существует" ,
70+ },
71+ )
72+ first_name = models .CharField (
73+ max_length = 255 , validators = [partial (user_name_validator , field_name = "Имя" )]
74+ )
75+ last_name = models .CharField (
76+ max_length = 255 , validators = [partial (user_name_validator , field_name = "Фамилия" )]
77+ )
6678 password = models .CharField (max_length = 255 )
6779 is_active = models .BooleanField (default = False , editable = False )
6880 user_type = models .PositiveSmallIntegerField (
@@ -74,7 +86,10 @@ class CustomUser(AbstractUser):
7486 editable = False ,
7587 )
7688 patronymic = models .CharField (
77- max_length = 255 , validators = [user_name_validator ], null = True , blank = True
89+ max_length = 255 ,
90+ validators = [partial (user_name_validator , field_name = "Отчество" )],
91+ null = True ,
92+ blank = True ,
7893 )
7994 # TODO need to be removed in future `key_skills` -> `skills`.
8095 key_skills = models .CharField (
@@ -87,7 +102,11 @@ class CustomUser(AbstractUser):
87102 "core.SkillToObject" ,
88103 related_query_name = "users" ,
89104 )
90- avatar = models .URLField (null = True , blank = True )
105+ avatar = models .URLField (
106+ null = True ,
107+ blank = True ,
108+ validators = [URLValidator (message = "Введите корректный URL" )],
109+ )
91110 birthday = models .DateField (
92111 validators = [user_birthday_validator ],
93112 )
0 commit comments