o
    Övÿhè  ã                   @   s‚   d dl Zd dlZd dlZd dlmZ G dd„ dejƒZG dd„ dejƒZG dd„ dejƒZ	G d	d
„ d
ejƒZ
G dd„ dejƒZdS )é    N)Úsettingsc                   @   sJ   e Zd Zejdd�Zejdddd�Zdddgdd	œgd
œZe	dd„ ƒZ
dS )ÚVehicleMakeModelT©ÚrequiredÚselfN)ÚnullÚdefaultÚvehiclemakemodelsÚnameÚparent©ÚfieldsÚunique©Ú
collectionÚindexesc                 C   s   t j| d�S )N)r   )r   Úobjects©r   © r   úE/var/www/html/Moveonwheels/move_on_wheels/vehiclemakemodels/models.pyÚchildren   s   zVehicleMakeModel.children)Ú__name__Ú
__module__Ú__qualname__ÚmeÚStringFieldr
   ÚReferenceFieldr   ÚmetaÚpropertyr   r   r   r   r   r      s    ÿþr   c                   @   sz   e Zd Zejddd�Zejddddd�Zejddd�Ze ¡ Z	dd„ Z
dd„ Zd	d
„ Zedd„ ƒZddgddœgdœZdS )ÚVehicleMakeT©r   r   F©r   r   Úblankr   c                 C   ó   | j r| j  ¡ | _ d S d S ©N©r
   Úupperr   r   r   r   Úclean   ó   ÿzVehicleMake.cleanc                 C   ó¢   t j tjd¡}t j|dd� t j |j¡d }t 	¡ j
› |› �}t j ||¡}t|dƒ�}| ¡ D ]}| |¡ q2W d  ƒ n1 sDw   Y  d|› �| _dS )úy
        Save uploaded image under MEDIA_ROOT/vehiclemake/
        with a unique filename and update self.image.
        ÚvehiclemakeT©Úexist_oké   úwb+Nzvehiclemake/©ÚosÚpathÚjoinr   Ú
MEDIA_ROOTÚmakedirsÚsplitextr
   ÚuuidÚuuid4ÚhexÚopenÚchunksÚwriteÚimage©r   Úfile_objÚfolderÚextÚfilenameÚfilepathÚdestÚchunkr   r   r   Ú
save_image   ó   ÿÿzVehicleMake.save_imagec                 C   óT   | j r&tj tj¡}tj|dd� tj || j ¡}tj |¡r(t |¡ dS dS dS ©z)Remove image file from disk if it exists.Tr,   N©	r=   r1   r2   r3   r   r4   r5   ÚexistsÚremove©r   r@   rC   r   r   r   Údelete_image_file2   ó   ûzVehicleMake.delete_image_filec                 C   s   ddl m} |j| d�S )Nr.   )ÚVehicleModel)Úmake)ÚmodelsrP   r   )r   rP   r   r   r   rR   ;   s   zVehicleMake.modelsr+   r
   r   r   N)r   r   r   r   r   r
   ÚBooleanFieldÚstatusÚcompany_namer=   r'   rF   rN   r   rR   r   r   r   r   r   r      s    	
ÿÿ
þr   c                   @   st   e Zd Zejddd�Zejddddd�Zeje	dej
d�Zejdd�Zdd„ Zed	d
„ ƒZdddgddœgdœZdS )rP   Tr    Fr!   ©r   Úreverse_delete_ruler   c                 C   r#   r$   r%   r   r   r   r   r'   O   r(   zVehicleModel.cleanc                 C   s   ddl m} |j| d� ¡ S )Nr.   )ÚVehicleSubModel)Úmodel)rR   rX   r   Úall)r   rX   r   r   r   Ú	submodelsS   s   zVehicleModel.submodelsÚvehiclemodelr
   rQ   r   r   N)r   r   r   r   r   r
   rS   rT   r   r   ÚCASCADErQ   Útyper'   r   r[   r   r   r   r   r   rP   I   s    
ÿ
þrP   c                   @   st   e Zd Zejddd�Zejddddd�Ze ¡ Zej	e
dejd�Zdd„ Zdd	„ Zd
d„ ZdddgddœgdœZdS )rX   Tr    Fr!   rV   c                 C   r#   r$   r%   r   r   r   r   r'   f   r(   zVehicleSubModel.cleanc                 C   r)   )r*   ÚvehiclesubmodelTr,   r.   r/   Nzvehiclesubmodel/r0   r>   r   r   r   rF   j   rG   zVehicleSubModel.save_imagec                 C   rH   rI   rJ   rM   r   r   r   rN   }   rO   z!VehicleSubModel.delete_image_filer_   r
   rY   r   r   N)r   r   r   r   r   r
   rS   rT   r=   r   rP   r]   rY   r'   rF   rN   r   r   r   r   r   rX   _   s    
ÿ
þrX   c                   @   s    e Zd Zejedejdd�Zejdd�Z	ejdd�Z
ejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�Zejdd�ZddgddœgdœZd	S )
ÚVehicleAttributesT)r   rW   r   Fr   ÚvehicleattributesÚvehicler   r   N)r   r   r   r   r   rX   r]   rb   r   ÚfueltypeÚvehicletypeÚdisplacementÚweightÚmileageÚpowerÚtorqueÚcategoryÚtransmissionr   r   r   r   r   r`   �   s&    ý
ÿ
þr`   )Úmongoenginer   r1   r7   Údjango.confr   ÚDocumentr   r   rP   rX   r`   r   r   r   r   Ú<module>   s    4.