o
    6k~i                     @   s>   d dl mZ d dlmZ d dlmZmZ G dd dejZ	dS )    )models)gettext_lazy)MinValueValidatorMaxValueValidatorc                   @   s  e Zd ZdZejdejdeddZej	deddZ
ejed	d
ZejddededgeddZejedd
Zejedd
ZejdddeddZejededdZejdeddZejddZejddZG dd dZdd  Zed!d" Z ed#d$ Z!d%S )&OfferzOffer Modelzplaces.PlaceoffersPlace)	on_deleterelated_nameverbose_name   Title)
max_lengthr   Description)r         g        g      Y@zDiscount (%))
max_digitsdecimal_places
validatorsr   z
Start DatezEnd Datezoffers/TImage)	upload_toblanknullr   Terms)defaultr   r   z	Is Active)r   r   )auto_now_add)auto_nowc                   @   s@   e Zd ZedZedZdgZejdgdejg ddgZ	dS )z
Offer.Metar   Offersz-created_atplace)fields)	is_active
start_dateend_dateN)
__name__
__module____qualname___r   verbose_name_pluralorderingr   Indexindexes r+   r+   2/var/www/newdalilibackend/backend/offers/models.pyMeta   s    r-   c                 C   s   | j j d| j S )Nz - )r   nametitle)selfr+   r+   r,   __str__'   s   zOffer.__str__c                 C   s6   ddl m} | }| jo| j|  ko| jkS   S Nr   )timezone)django.utilsr3   nowr    r!   r"   )r0   r3   r5   r+   r+   r,   is_valid*   s   "zOffer.is_validc                 C   s*   ddl m} | jsd S | j|  }|jS r2   )r4   r3   r6   r"   r5   days)r0   r3   deltar+   r+   r,   days_remaining0   s
   zOffer.days_remainingN)"r#   r$   r%   __doc__r   
ForeignKeyCASCADEr&   r   	CharFieldr/   	TextFielddescriptionDecimalFieldr   r   discountDateTimeFieldr!   r"   
ImageFieldimage	JSONFielddicttermsBooleanFieldr    
created_at
updated_atr-   r1   propertyr6   r9   r+   r+   r+   r,   r      s:    	
r   N)
	django.dbr   django.utils.translationr   r&   django.core.validatorsr   r   Modelr   r+   r+   r+   r,   <module>   s    