3
Lâ^7  ã               @   sP   d dl mZ d dlmZ d dlT d dlZG dd„ dejƒZG dd„ dejƒZdS )	é    )Úserializers)ÚUser)Ú*Nc               @   s2   e Zd ZdZejejjƒ dd�Z	G dd„ dƒZ
dS )ÚUserInfoSerializerz
	Serializer for the UserInfo
	Úid)ÚquerysetÚ
slug_fieldc               @   s   e Zd ZeZdZdS )zUserInfoSerializer.MetaÚ__all__N)Ú__name__Ú
__module__Ú__qualname__ÚUserInfoÚmodelÚfields© r   r   úA/var/www/html/myproject/userapp/serializers/userapp_serializer.pyÚMeta   s   r   N)r
   r   r   Ú__doc__r   ÚSlugRelatedFieldr   ÚobjectsÚallÚuser_idr   r   r   r   r   r      s   r   c               @   sf   e Zd ZdZejejjƒ dd�Z	eje
jjƒ dd�Zejƒ Zejƒ Zdd„ Zdd„ ZG dd	„ d	ƒZd
S )ÚUserPostSerializerz
	Serializer for the UserInfo
	r   )r   r   c             C   s^   y.t jj|jjjd�jƒ }|r(t|jƒS dS W n* t	k
rX } zt
d|ƒ dS d }~X nX d S )N)r   Ú Úer)r   r   ÚfilterÚuserinfo_idr   r   ÚfirstÚstrÚusernameÚ	ExceptionÚprint)ÚselfÚobjÚuserÚer   r   r   Úget_user_name   s    

z UserPostSerializer.get_user_namec             C   s`   y0t jjt|jjƒd�jƒ }|r*t|jƒS dS W n* t	k
rZ } zt
d|ƒ dS d }~X nX d S )N)r   r   r   )ÚKeyboardr   r   ÚintÚkeyboard_idr   r   r   Úlabelr    r!   )r"   r#   Úkeyboard_namer%   r   r   r   Úget_keyboard_name&   s    

z$UserPostSerializer.get_keyboard_namec               @   s   e Zd ZeZdZdS )zUserPostSerializer.Metar	   N)r
   r   r   ÚUserAddedPostr   r   r   r   r   r   r   1   s   r   N)r
   r   r   r   r   r   r   r   r   r   r'   r)   ÚSerializerMethodFieldr+   Z	user_namer&   r,   r   r   r   r   r   r      s   r   )	Úrest_frameworkr   Údjango.contrib.auth.modelsr   Úuserapp.modelsÚdatetimeÚModelSerializerr   r   r   r   r   r   Ú<module>   s
   
