
    pi(                         d dl mZ d dlmZ d dlmZ  G d dej                        Z G d dej                        Z G d d	ej                        Z	 G d
 dej                        Z
y)    )models)slugify)reversec                   &    e Zd Z ej                  dd      Z ej                  ddd      Z ej                  ddd      Z	 ej                  d      Z ej                  d      Z ej                  d	      Z G d
 d      Z fdZd Z xZS )Brandd   T)
max_lengthuniquer	   r
   blankzbrands/	upload_tor   nullr   defaultauto_now_addc                       e Zd ZdgZy)
Brand.MetanameN__name__
__module____qualname__ordering     (/var/www/alwasay/apps/products/models.pyMetar      s	    8r   r    c                 p    | j                   st        | j                        | _         t        |   |i | y Nslugr   r   supersaveselfargskwargs	__class__s      r   r&   z
Brand.save   +    yy		*DId%f%r   c                     | j                   S r"   r   r(   s    r   __str__zBrand.__str__       yyr   )r   r   r   r   	CharFieldr   	SlugFieldr$   
ImageFieldlogo	TextFielddescriptionBooleanField	is_activeDateTimeField
created_atr    r&   r0   __classcell__r+   s   @r   r   r      s    6s48D6s4tDD6y4HD"&"".K###D1I%%%48J &
r   r   c                      e Zd Z ej                  d      Z ej                  ddd      Z ej                  ddd      Z	 ej                  d      Z ej                  dej                  ddd	
      Z ej                  dd      Z ej"                  d      Z ej"                  dd      Z ej(                  d      Z G d d      Zy)Categoryr   r	   Tr   zcategories/r   r   r(   children	on_deleter   r   related_namer   z*Display order (lower numbers appear first)r   	help_textr   FzEShow this subcategory in the parent category's dropdown menu (max 10)r   c                       e Zd ZdZdZddgZy)Category.Metar?   
Categoriesorderr   N)r   r   r   verbose_nameverbose_name_pluralr   r   r   r   r    rH   .   s    !*V$r   r    N)r   r   r   r   r2   r   r3   r$   r4   imager6   r7   
ForeignKeyCASCADEparentPositiveIntegerFieldrJ   r8   r9   show_in_menur:   r;   r    r   r   r   r?   r?      s    6s+D6s4tDDFTME"&"".KV..F (F''=ijE###D1I&6&&YL &%%48J% %r   r?   c                   f    e Zd Z G d dej                        Z ej                  d      Z ej                  ddd      Z	 ej                  ddd	      Z
 ej                  d
dd      Z ej                  dd      Z ej                  dd      Z ej                  d      Z ej"                  eej&                  dd      Z ej"                  eej&                  ddd      Z ej.                  dddd      Z ej.                  dddd      Z ej4                  ddd      Z ej4                  ddd      Z ej:                  ddd      Z ej                  dd      Z ej                  dej@                  ejB                         Z" ej                  d!      Z# ej                  dd      Z$ ej                  d"d      Z% ejL                  d#      Z' ejL                  d$      Z( G d% d&      Z) fd'Z*d( Z+d) Z,e-d*        Z.e-d+        Z/e-d,        Z0e-d-        Z1e-d.        Z2 xZ3S )/Productc                       e Zd ZdZdZdZdZy)Product.Status)draftDraft)activeActive)out_of_stockzOut of Stock)discontinuedDiscontinuedN)r   r   r   DRAFTACTIVEOUT_OF_STOCKDISCONTINUEDr   r   r   StatusrV   5   s     #55r   rb      r@   Tr   2   zStock Keeping Unit)r	   r
   rF   r   zOEM Part Number)r	   r   rF   Fz:Show in Top Rated Products section on landing page (max 3)rE   i  r	   r   r   products)rC   r   rD   rB   
      )
max_digitsdecimal_placesr   r   r   )r   r   r   products/%Y/%m/r   z*List compatible vehicle makes/models/years)r   rF      )r	   choicesr   r      r   )auto_nowc                       e Zd ZdgZ ej
                  dg       ej
                  dg       ej
                  dg      gZy)Product.Metaz-created_atr$   )fieldsskuN)r   r   r   r   r   Indexindexesr   r   r   r    rq   h   s@    !?FLL)FLL(FLL0
r   r    c                 p    | j                   st        | j                        | _         t        |   |i | y r"   r#   r'   s      r   r&   zProduct.savep   r,   r   c                     | j                   S r"   r.   r/   s    r   r0   zProduct.__str__u   r1   r   c                 4    t        dd| j                  i      S )Nzproducts:product_detailr$   )r*   )r   r$   r/   s    r   get_absolute_urlzProduct.get_absolute_urlx   s    0&$))9LMMr   c                 t    | j                   d uxr) | j                  d uxr | j                   | j                  k  S r"   )
sale_pricepricer/   s    r   
is_on_salezProduct.is_on_sale{   s4    d*ftzz/Ef$//\`\f\fJffr   c                 J    | j                   r| j                  S | j                  S r"   )r}   r{   r|   r/   s    r   current_pricezProduct.current_price   s    ????"zzr   c                     | j                   r>| j                  r2t        | j                  | j                  z
  | j                  z  dz        S y)Nr   r   )r}   r|   intr{   r/   s    r   discount_percentagezProduct.discount_percentage   s8    ??tzzdoo5CsJKKr   c                 :    | j                   y| j                   dkD  S )NTr   )stock_quantityr/   s    r   is_in_stockzProduct.is_in_stock   s"    &""Q&&r   c                 f    | j                   | j                  y| j                   | j                  k  S )NF)r   low_stock_thresholdr/   s    r   is_low_stockzProduct.is_low_stock   s3    &$*B*B*J""d&>&>>>r   )4r   r   r   r   TextChoicesrb   r2   r   r3   r$   rs   part_numberr8   is_top_ratedr6   short_descriptionr7   rN   r?   SET_NULLcategoryr   brandDecimalFieldr|   r{   rQ   r   r   r4   
main_imagecompatible_vehiclesrm   r^   statusis_featured
meta_titlemeta_descriptionr:   r;   
updated_atr    r&   r0   ry   propertyr}   r   r   r   r   r<   r=   s   @r   rT   rT   4   s   6## 6 6s+D6s4tDD
&

bAU
VC"&""cIZ[K&6&&u@|}L(((CtD"&"".K v  //	H F//E  F2atRVWE$$$1DW[\J0V00$TRN5&55bSWX"""->dQUVJ*&**>
 VV^^V\\ZF%&%%e4K!!!S=J'v''3dC%%%48J%%%t4J
 
&
N g g  
  
 ' '
 ? ?r   rT   c                   $   e Zd Z ej                  eej                  d      Z ej                  d      Z	 ej                  dd      Z ej                  d	      Z ej                  d
	      Z ej                   d      Z G d d      Zd Zy)ProductImageimages)rC   rD   rk   )r   rc   Tre   Fr   r   r   c                       e Zd ZddgZy)ProductImage.MetarJ   r;   Nr   r   r   r   r    r      s    \*r   r    c                 L    | j                   j                   d| j                   S )Nz	 - Image )productr   rJ   r/   s    r   r0   zProductImage.__str__   s"    ,,##$Idjj\::r   N)r   r   r   r   rN   rT   rO   r   r4   rM   r2   alt_textr8   
is_primaryrQ   rJ   r:   r;   r    r0   r   r   r   r   r      s    f..G
 F(9:Ev3d;H$$$U3J'F''2E%%%48J+ +;r   r   N)	django.dbr   django.utils.textr   django.urlsr   Modelr   r?   rT   r   r   r   r   <module>r      sQ     % FLL (%v|| %4a?fll a?H;6<< ;r   