o
    mi                     @   sn   d dl mZmZ d dlmZ d dlmZ G dd deZG dd dejZG dd	 d	eZ	G d
d deZ
dS )    )ContractorType
Contractor)serializers)ModelSerializerc                   @   s6   e Zd ZejdddZejdddZG dd dZdS )	ContractorListAPISerializerz	type.nameT)source
allow_nullget_created_by_full_name)r   	read_onlyc                   @   s   e Zd ZeZdZeZdS )z ContractorListAPISerializer.Meta)idnametypephone_noemail
created_by
deleted_atnoteN)__name__
__module____qualname__r   modelfieldsread_only_fields r   r   X/var/www/html/kuke-dev/django-kuke/apps/contractor/serializers/contractor_serializers.pyMeta   s    r   N)r   r   r   r   	CharFieldr   r   r   r   r   r   r   r      s    r   c                   @   s,   e Zd Zejej dZG dd dZ	dS )ContractorSerializer)querysetc                   @      e Zd ZeZdZdS )zContractorSerializer.Metar   r   r   r   Nr   r   r   r   r   r   r   r   r   r   r          r   N)
r   r   r   r   PrimaryKeyRelatedFieldr   objectsallr   r   r   r   r   r   r      s    r   c                       s8   e Zd ZejdddZG dd dZ fddZ  ZS )ContractorStoreAPISerializerT)required
write_onlyc                   @   r   )z!ContractorStoreAPISerializer.Meta)r   r   r   r   r   r   Nr!   r   r   r   r   r      r"   r   c                    s   d|v r| d rtjj|d d }|stdditjj| ddj	| j
r0| j
jnd d r=tddit |S )Nr   )r   Zinvalid_contractorzPlease enter proper contractor!r   )r   z,A contractor with this email already exists.)get	isnumericr   r$   filterfirstr   ValidationErrorr   excludeinstancer   existssupervalidate)selfattrsZcontractor_type	__class__r   r   r2   !   s   .z%ContractorStoreAPISerializer.validate)	r   r   r   r   r   r   r   r2   __classcell__r   r   r5   r   r&      s    r&   c                   @   s   e Zd ZG dd dZdS )ContractorDeleteAPISerializerc                   @   r   )z"ContractorDeleteAPISerializer.Metar    Nr!   r   r   r   r   r   /   r"   r   N)r   r   r   r   r   r   r   r   r8   .   s    r8   N)apps.contractor.modelsr   r   rest_frameworkr   rest_framework.serializersr   r   r   r&   r8   r   r   r   r   <module>   s    
	