3
g                 @   s   d dl mZ d dlmZ d dlmZ d dlmZm	Z	m
Z
 G dd dejZG dd dejZG d	d
 d
eZG dd dejjZG dd dejZG dd dejZdS )    )models)now)gettext_lazy)AutoSlugFieldCreationDateTimeFieldModificationDateTimeFieldc                   sF   e Zd ZdZeedZeedZ fddZ	G dd dZ
  ZS )TimeStampedModelz|
    TimeStampedModel

    An abstract base class model that provides self-managed "created" and
    "modified" fields.
    createdmodifiedc                s(   |j dt| dd| _t jf | d S )Nupdate_modifiedT)popgetattrr   supersave)selfkwargs)	__class__ Y/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django_extensions/db/models.pyr      s    zTimeStampedModel.savec               @   s   e Zd ZdZdZdS )zTimeStampedModel.Metar
   TN)__name__
__module____qualname__Zget_latest_byabstractr   r   r   r   Meta   s   r   )r   r   r   __doc__r   _r	   r   r
   r   r   __classcell__r   r   )r   r   r   	   s
   r   c               @   sD   e Zd ZdZejedddZejeddddZ	G dd	 d	Z
d
S )TitleDescriptionModelzm
    TitleDescriptionModel

    An abstract base class model that provides title and description fields.
    title   )
max_lengthdescriptionT)blanknullc               @   s   e Zd ZdZdS )zTitleDescriptionModel.MetaTN)r   r   r   r   r   r   r   r   r   '   s   r   N)r   r   r   r   r   Z	CharFieldr   r   Z	TextFieldr!   r   r   r   r   r   r      s   r   c               @   s.   e Zd ZdZeedddZG dd dZdS )TitleSlugDescriptionModela  
    TitleSlugDescriptionModel

    An abstract base class model that provides title and description fields
    and a self-managed "slug" field that populates from the title.

    .. note ::
        If you want to use custom "slugify" function, you could
        define ``slugify_function`` which then will be used
        in :py:class:`AutoSlugField` to slugify ``populate_from`` field.

        See :py:class:`AutoSlugField` for more details.
    slugr   )Zpopulate_fromc               @   s   e Zd ZdZdS )zTitleSlugDescriptionModel.MetaTN)r   r   r   r   r   r   r   r   r   <   s   r   N)r   r   r   r   r   r   r%   r   r   r   r   r   r$   +   s   r$   c               @   s    e Zd ZdZdd Zdd ZdS )ActivatorQuerySetzH
    ActivatorQuerySet

    Query set that returns statused results
    c             C   s   | j tjdS )z Return active query set )status)filterActivatorModelACTIVE_STATUS)r   r   r   r   activeG   s    zActivatorQuerySet.activec             C   s   | j tjdS )z Return inactive query set )r'   )r(   r)   INACTIVE_STATUS)r   r   r   r   inactiveK   s    zActivatorQuerySet.inactiveN)r   r   r   r   r+   r-   r   r   r   r   r&   @   s   r&   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ActivatorModelManagerz|
    ActivatorModelManager

    Manager to return instances of ActivatorModel: SomeModel.objects.active() / .inactive()
    c             C   s   t | j| jdS )z' Use ActivatorQuerySet for all results )modelZusing)r&   r/   _db)r   r   r   r   get_querysetW   s    z"ActivatorModelManager.get_querysetc             C   s   | j  j S )z
        Return active instances of ActivatorModel:

        SomeModel.objects.active(), proxy to ActivatorQuerySet.active
        )r1   r+   )r   r   r   r   r+   [   s    zActivatorModelManager.activec             C   s   | j  j S )z
        Return inactive instances of ActivatorModel:

        SomeModel.objects.inactive(), proxy to ActivatorQuerySet.inactive
        )r1   r-   )r   r   r   r   r-   c   s    zActivatorModelManager.inactiveN)r   r   r   r   r1   r+   r-   r   r   r   r   r.   P   s   r.   c                   s   e Zd ZdZdZdZeedfeedffZej	edeedZ
ejdded	d
Zejddedd
Ze ZG dd dZ fddZ  ZS )r)   zh
    ActivatorModel

    An abstract base class model that provides activate and deactivate fields.
    r      ZInactiveZActiver'   )choicesdefaultTz&keep empty for an immediate activation)r"   r#   	help_textz$keep empty for indefinite activationc               @   s   e Zd ZdZdZdS )zActivatorModel.Metar'   -activate_dateTN)r'   r6   )r   r   r   Zorderingr   r   r   r   r   r      s   r   c                s    | j st | _ t j|| d S )N)activate_dater   r   r   )r   argsr   )r   r   r   r      s    zActivatorModel.save)r   r   r   r   r,   r*   r   ZSTATUS_CHOICESr   ZIntegerFieldr'   ZDateTimeFieldr7   Zdeactivate_dater.   Zobjectsr   r   r   r   r   )r   r   r)   l   s   
r)   N)Z	django.dbr   Zdjango.utils.timezoner   Zdjango.utils.translationr   r   Zdjango_extensions.db.fieldsr   r   r   ZModelr   r   r$   queryZQuerySetr&   Managerr.   r)   r   r   r   r   <module>   s   