3
g+                 @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 G dd	 d	e
ZG d
d deZG dd deZG dd deZdS )al  
"Rel objects" for related fields.

"Rel objects" (for lack of a better name) carry information about the relation
modeled by a related field and provide some utility functions. They're stored
in the ``remote_field`` attribute of the field.

They also act as reverse fields for the purposes of the Meta API because
they're the closest concept currently available.
    )
exceptions)cached_property)make_hashable   )BLANK_CHOICE_DASH)FieldCacheMixinc               @   s,  e Zd ZdZdZdZdZdZdZdZ	d7ddZ
edd Zed	d
 Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zdd Zdd Zedd Zdd  Zed!d" Zd#d$ Zd%d& Zdedf fd'd(Zd)d* Zd+d, Z d-d. Z!d/d0 Z"d8d1d2Z#d9d3d4Z$d5d6 Z%dS ):ForeignObjectRelz
    Used by ForeignObject to store information about the relation.

    ``_meta.get_fields()`` returns this class to provide access to the field
    flags for the reverse relation.
    TFNc             C   sF   || _ || _|| _|| _|d kr$i n|| _|| _|| _d| _d| _d S )NFT)	fieldmodelrelated_namerelated_query_namelimit_choices_toparent_link	on_deletesymmetricalmultiple)selfr	   tor   r   r   r   r    r   e/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/db/models/fields/reverse_related.py__init__'   s    zForeignObjectRel.__init__c             C   s   | j  S )N)	is_hidden)r   r   r   r   hidden8   s    zForeignObjectRel.hiddenc             C   s
   | j j S )N)r	   r   )r   r   r   r   name<   s    zForeignObjectRel.namec             C   s   | j S )N)r	   )r   r   r   r   remote_field@   s    zForeignObjectRel.remote_fieldc             C   s,   | j  d j}t|dkr$tjd|d S )z
        When filtering against this relation, return the field on the remote
        model against which the filtering should happen.
        r   z1Can't use target_field for multicolumn relations.r   )get_path_infotarget_fieldslenr   Z
FieldError)r   r   r   r   r   target_fieldD   s    
zForeignObjectRel.target_fieldc             C   s   | j jstd| j jS )NzVThis property can't be accessed before self.field.contribute_to_class has been called.)r	   r
   AttributeError)r   r   r   r   related_modelO   s    zForeignObjectRel.related_modelc             C   s   | j jS )N)r	   many_to_many)r   r   r   r   r"   V   s    zForeignObjectRel.many_to_manyc             C   s   | j jS )N)r	   one_to_many)r   r   r   r   many_to_oneZ   s    zForeignObjectRel.many_to_onec             C   s   | j jS )N)r	   r$   )r   r   r   r   r#   ^   s    zForeignObjectRel.one_to_manyc             C   s   | j jS )N)r	   
one_to_one)r   r   r   r   r%   b   s    zForeignObjectRel.one_to_onec             C   s   | j j|S )N)r	   
get_lookup)r   lookup_namer   r   r   r&   f   s    zForeignObjectRel.get_lookupc             C   s
   | j j S )N)r	   get_internal_type)r   r   r   r   r(   i   s    z"ForeignObjectRel.get_internal_typec             C   s   | j jS )N)r	   db_type)r   r   r   r   r)   l   s    zForeignObjectRel.db_typec             C   s    dt | j| jjj| jjjf S )Nz<%s: %s.%s>)type__name__r!   _metaZ	app_label
model_name)r   r   r   r   __repr__p   s    zForeignObjectRel.__repr__c          	   C   s,   | j | j| j| jt| j| j| j| j| j	f	S )N)
r	   r
   r   r   r   r   r   r   r   r   )r   r   r   r   identityw   s    zForeignObjectRel.identityc             C   s   t || jstS | j|jkS )N)
isinstance	__class__NotImplementedr/   )r   otherr   r   r   __eq__   s    zForeignObjectRel.__eq__c             C   s
   t | jS )N)hashr/   )r   r   r   r   __hash__   s    zForeignObjectRel.__hash__c             C   s@   |p| j }| jjj|}|r&|j| }|r.|ng dd |D  S )a  
        Return choices with a default blank choices included, for use
        as <select> choices for this field.

        Analog of django.db.models.fields.Field.get_choices(), provided
        initially for utilization by RelatedFieldListFilter.
        c             S   s   g | ]}|j t|fqS r   )pkstr).0xr   r   r   
<listcomp>   s    z0ForeignObjectRel.get_choices.<locals>.<listcomp>)r   r!   Z_default_managerZcomplex_filterZorder_by)r   Zinclude_blankZblank_choicer   Zorderingqsr   r   r   get_choices   s    


zForeignObjectRel.get_choicesc             C   s   t | jo| jd dkS )z$Should the related object be hidden?r   +r   )boolr   )r   r   r   r   r      s    zForeignObjectRel.is_hiddenc             C   s
   | j j S )N)r	   Zget_reverse_joining_columns)r   r   r   r   get_joining_columns   s    z$ForeignObjectRel.get_joining_columnsc             C   s   | j j|||S )N)r	   get_extra_restriction)r   Zwhere_classaliasZrelated_aliasr   r   r   rA      s    z&ForeignObjectRel.get_extra_restrictionc             C   s
   d| _ dS )z
        Set the related field's name, this is not available until later stages
        of app loading, so set_field_name is called from
        set_attributes_from_rel()
        N)
field_name)r   r   r   r   set_field_name   s    zForeignObjectRel.set_field_namec             C   sV   |r
|j n| jj }|p| j}| jr6| jr6|| jkr6d S | jrB| jS |j| jrPdnd S )NZ_set )r,   r!   r   r   r
   r   r-   )r   r
   optsr   r   r   get_accessor_name   s    
z"ForeignObjectRel.get_accessor_namec             C   s   | j j|S )N)r	   Zget_reverse_path_info)r   Zfiltered_relationr   r   r   r      s    zForeignObjectRel.get_path_infoc             C   s   | j  S )z
        Return the name of the cache key to use for storing an instance of the
        forward model on the reverse model.
        )rG   )r   r   r   r   get_cache_name   s    zForeignObjectRel.get_cache_name)NNNFN)N)N)&r+   
__module____qualname____doc__Zauto_createdconcreteeditableZis_relationnullZempty_strings_allowedr   r   r   r   propertyr   r   r!   r"   r$   r#   r%   r&   r(   r)   r.   r/   r4   r6   r   r=   r   r@   rA   rD   rG   r   rH   r   r   r   r   r      sD    



r   c                   sJ   e Zd ZdZd fdd	Zdd Ze fdd	Zd
d Zdd Z	  Z
S )ManyToOneRela+  
    Used by the ForeignKey field to store information about the relation.

    ``_meta.get_fields()`` returns this class to provide access to the field
    flags for the reverse relation.

    Note: Because we somewhat abuse the Rel objects by using them as reverse
    fields we get the funny situation where
    ``ManyToOneRel.many_to_one == False`` and
    ``ManyToOneRel.one_to_many == True``. This is unfortunate but the actual
    ManyToOneRel class is a private API and there is work underway to turn
    reverse relations into actual fields.
    NFc	       	   	      s$   t  j|||||||d || _d S )N)r   r   r   r   r   )superr   rC   )	r   r	   r   rC   r   r   r   r   r   )r1   r   r   r      s    zManyToOneRel.__init__c             C   s   | j j }|jdd  |S )Nr!   )__dict__copypop)r   stater   r   r   __getstate__   s    
zManyToOneRel.__getstate__c                s   t  j| jf S )N)rQ   r/   rC   )r   )r1   r   r   r/      s    zManyToOneRel.identityc             C   s*   | j jj| j}|js&tjd| j |S )zY
        Return the Field in the 'to' object to which this relationship is tied.
        zNo related field named '%s')r
   r,   	get_fieldrC   rL   r   ZFieldDoesNotExist)r   r	   r   r   r   get_related_field   s    zManyToOneRel.get_related_fieldc             C   s   | j p| jjjj| _ d S )N)rC   r
   r,   r7   r   )r   r   r   r   rD      s    zManyToOneRel.set_field_name)NNNFN)r+   rI   rJ   rK   r   rV   rO   r/   rX   rD   __classcell__r   r   )r1   r   rP      s    	rP   c                   s"   e Zd ZdZd fdd	Z  ZS )OneToOneRelz
    Used by OneToOneField to store information about the relation.

    ``_meta.get_fields()`` returns this class to provide access to the field
    flags for the reverse relation.
    NFc	       	   
      s&   t  j||||||||d d| _d S )N)r   r   r   r   r   F)rQ   r   r   )	r   r	   r   rC   r   r   r   r   r   )r1   r   r   r   
  s    zOneToOneRel.__init__)NNNFN)r+   rI   rJ   rK   r   rY   r   r   )r1   r   rZ     s    rZ   c                   s:   e Zd ZdZd
 fdd	Ze fddZdd	 Z  ZS )ManyToManyRelz
    Used by ManyToManyField to store information about the relation.

    ``_meta.get_fields()`` returns this class to provide access to the field
    flags for the reverse relation.
    NTc
       
         sV   t  j|||||d |r(|	 r(td|| _|r@| r@td|| _|| _|	| _d S )N)r   r   r   z4Can't supply a through model and db_constraint=Falsez5Cannot specify through_fields without a through model)rQ   r   
ValueErrorthroughthrough_fieldsr   db_constraint)
r   r	   r   r   r   r   r   r]   r^   r_   )r1   r   r   r      s    

zManyToManyRel.__init__c                s   t  j| jt| j| jf S )N)rQ   r/   r]   r   r^   r_   )r   )r1   r   r   r/   5  s    zManyToManyRel.identityc             C   sX   | j j}| jr |j| jd }n.x,|jD ]"}t|dd}|r(|j| jkr(P q(W |jd S )z
        Return the field in the 'to' object to which this relationship is tied.
        Provided for symmetry with ManyToOneRel.
        r   r   N)r]   r,   r^   rW   fieldsgetattrr
   Zforeign_related_fields)r   rF   r	   relr   r   r   rX   =  s    zManyToManyRel.get_related_field)NNNTNNT)	r+   rI   rJ   rK   r   rO   r/   rX   rY   r   r   )r1   r   r[     s     r[   N)rK   Zdjango.corer   Zdjango.utils.functionalr   Zdjango.utils.hashabler   rE   r   Zmixinsr   r   rP   rZ   r[   r   r   r   r   <module>
   s    =2