
    3Di                     F    d dl mZ ddlmZ  G d dej                        Zy)    )serializers   )UserProfilec                       e Zd Z ej                  dd      Z ej                  dd      Z ej                  dd      Z G d d      Zd Z	y	)
UserProfileSerializerzuser.usernameT)source	read_onlyz
user.emailzuser.user_typec                       e Zd ZeZdZdZy)UserProfileSerializer.Meta__all__)user
created_at
updated_atN)__name__
__module____qualname__r   modelfieldsread_only_fields     E/var/www/html/dp2/backend_v2.1/server/apps/userprofile/serializers.pyMetar      s    ?r   r   c                     |s|S t         j                  j                  |      }| j                  r&|j	                  | j                  j
                        }|j                         rt        j                  d      |S )zFValidate phone number is unique across all profiles except current one)phone_number)pkz-A user with this phone number already exists.)	r   objectsfilterinstanceexcluder   existsr   ValidationError)selfvalueqss      r   validate_phone_numberz+UserProfileSerializer.validate_phone_number   sd    L  ''U';==t}}//0B99;--.]^^r   N)
r   r   r   r   	CharFieldusernameemail	user_typer   r&   r   r   r   r   r      sP    ${$$OtLH!K!!FE%%%-=NI@ @r   r   N)rest_frameworkr   modelsr   ModelSerializerr   r   r   r   <module>r.      s    & K77 r   