a
    ÆZEgã  ã                   @   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,   |  dt| ddƒ¡| _tƒ jf i |¤Ž d S )NÚupdate_modifiedT)ÚpopÚgetattrr   ÚsuperÚsave)ÚselfÚkwargs©Ú	__class__© úT/var/www/sistema_ama/venv/lib/python3.9/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.MetaTNr%   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_STATUSr.   r   r   r   ÚinactiveK   s    zActivatorQuerySet.inactiveN)r   r   r   r   r/   r1   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(   r3   Ú_dbr.   r   r   r   Úget_querysetW   s    z"ActivatorModelManager.get_querysetc                 C   s   |   ¡  ¡ S )zƒ
        Return active instances of ActivatorModel:

        SomeModel.objects.active(), proxy to ActivatorQuerySet.active
        )r5   r/   r.   r   r   r   r/   [   s    zActivatorModelManager.activec                 C   s   |   ¡  ¡ S )z‰
        Return inactive instances of ActivatorModel:

        SomeModel.objects.inactive(), proxy to ActivatorQuerySet.inactive
        )r5   r1   r.   r   r   r   r1   c   s    zActivatorModelManager.inactiveN)r   r   r   r   r5   r/   r1   r   r   r   r   r2   P   s   r2   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.Meta)r*   z-activate_dateTN)r   r   r   Zorderingr   r   r   r   r   r      s   r   c                    s$   | j stƒ | _ tƒ j|i |¤Ž d S )N)Úactivate_dater   r   r   )r   Úargsr   r   r   r   r   ƒ   s    zActivatorModel.save)r   r   r   r   r0   r-   r   ZSTATUS_CHOICESr   ZIntegerFieldr*   ZDateTimeFieldr:   Zdeactivate_dater2   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(   ÚManagerr2   r,   r   r   r   r   Ú<module>   s   