o
    ÕèFh&2  ã                   @   s˜   d Z ddl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 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.
é    N)Ú
exceptions)ÚRemovedInDjango60Warning)Úcached_property)Úmake_hashableé   )ÚBLANK_CHOICE_DASH)ÚFieldCacheMixinc                   @   sb  e Zd ZdZdZdZdZdZdZdZ						dBd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dd„ Zdd „ Zed!d"„ ƒZd#d$„ Zed%d&„ ƒZd'd(„ Zd)d*„ Zd+d,„ Zde dd-fd.d/„Z!d0d1„ Z"d2d3„ Z#d4d5„ Z$d6d7„ Z%d8d9„ Z&dCd:d;„Z'dCd<d=„Z(ed>d?„ ƒZ)d@dA„ Z*dS )DÚ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 u 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   ú`/var/www/html/loop/nvenv/lib/python3.10/site-packages/django/db/models/fields/reverse_related.pyÚ__init__*   s   

zForeignObjectRel.__init__c                 C   ó   |   ¡ S ©N)Ú	is_hidden©r   r   r   r   ÚhiddenC   ó   zForeignObjectRel.hiddenc                 C   ó
   | j  ¡ S r   )r
   r   r   r   r   r   ÚnameG   s   
zForeignObjectRel.namec                 C   s   | j S r   )r
   r   r   r   r   Úremote_fieldK   s   zForeignObjectRel.remote_fieldc                 C   s*   | j d j}t|ƒdkrt 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   )Ú
path_infosÚtarget_fieldsÚlenr   Ú
FieldError)r   r#   r   r   r   Útarget_fieldO   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   ÚAttributeErrorr   r   r   r   Úrelated_model\   s
   ÿzForeignObjectRel.related_modelc                 C   ó   | j jS r   )r
   Úmany_to_manyr   r   r   r   r*   e   r   zForeignObjectRel.many_to_manyc                 C   r)   r   )r
   Úone_to_manyr   r   r   r   Úmany_to_onei   r   zForeignObjectRel.many_to_onec                 C   r)   r   )r
   r,   r   r   r   r   r+   m   r   zForeignObjectRel.one_to_manyc                 C   r)   r   )r
   Ú
one_to_oner   r   r   r   r-   q   r   zForeignObjectRel.one_to_onec                 C   ó   | j  |¡S r   )r
   Ú
get_lookup)r   Úlookup_namer   r   r   r/   u   ó   zForeignObjectRel.get_lookupc                 C   r   r   )r
   Úget_lookupsr   r   r   r   r2   x   ó   
zForeignObjectRel.get_lookupsc                 C   r.   r   )r
   Úget_transform)r   r   r   r   r   r4   {   r1   zForeignObjectRel.get_transformc                 C   r   r   )r
   Úget_internal_typer   r   r   r   r5   ~   r3   z"ForeignObjectRel.get_internal_typec                 C   r)   r   )r
   Údb_typer   r   r   r   r6   �   r   zForeignObjectRel.db_typec                 C   s    dt | ƒj| jjj| jjjf S )Nz<%s: %s.%s>)ÚtypeÚ__name__r(   Ú_metaÚ	app_labelÚ
model_namer   r   r   r   Ú__repr__…   s
   ýzForeignObjectRel.__repr__c              	   C   s,   | j | j| j| jt| jƒ| j| j| j| j	f	S r   )
r
   r   r   r   r   r   r   r   r   r   r   r   r   r   ÚidentityŒ   s   ÷zForeignObjectRel.identityc                 C   s   t || jƒstS | j|jkS r   )Ú
isinstanceÚ	__class__ÚNotImplementedr=   )r   Úotherr   r   r   Ú__eq__š   s   zForeignObjectRel.__eq__c                 C   s
   t | jƒS r   )Úhashr=   r   r   r   r   Ú__hash__Ÿ   r3   zForeignObjectRel.__hash__c                 C   s   | j  ¡ }| dd ¡ |S )Nr"   )Ú__dict__ÚcopyÚpop©r   Ústater   r   r   Ú__getstate__¢   s   
zForeignObjectRel.__getstate__r   c                 C   s@   |p| 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(   Ú_default_managerÚcomplex_filterÚorder_by)r   Úinclude_blankÚblank_choicer   Ú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!   ú+)Úboolr   r   r   r   r   r   Â   s   zForeignObjectRel.is_hiddenc                 C   s   t  dt¡ | j ¡ S )NzWForeignObjectRel.get_joining_columns() is deprecated. Use get_joining_fields() instead.)ÚwarningsÚwarnr   r
   Úget_reverse_joining_columnsr   r   r   r   Úget_joining_columnsÆ   s
   ý
z$ForeignObjectRel.get_joining_columnsc                 C   r   r   )r
   Úget_reverse_joining_fieldsr   r   r   r   Úget_joining_fieldsÎ   r3   z#ForeignObjectRel.get_joining_fieldsc                 C   s   | j  ||¡S r   )r
   Úget_extra_restriction)r   ÚaliasÚrelated_aliasr   r   r   r`   Ñ   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_namer   r   r   r   Úset_field_nameÔ   s   
zForeignObjectRel.set_field_namec                 C   sX   |r|j n| jj }|p| j}| jr| jr|| jkrd S | jr!| jS |j| jr)d S d S )NÚ_setÚ )r9   r(   r   r   r   r   r;   )r   r   Úoptsr   r   r   Úget_accessor_nameÞ   s   
z"ForeignObjectRel.get_accessor_namec                 C   s   |r| j  |¡S | j jS r   )r
   Úget_reverse_path_infoÚreverse_path_infos)r   Úfiltered_relationr   r   r   Úget_path_infoð   s   zForeignObjectRel.get_path_infoc                 C   r   r   )rl   r   r   r   r   r"   ö   r   zForeignObjectRel.path_infosc                 C   r   )z„
        Return the name of the cache key to use for storing an instance of the
        forward model on the reverse model.
        )rh   r   r   r   r   Úget_cache_nameú   s   zForeignObjectRel.get_cache_name©NNNFNr   )+r8   Ú
__module__Ú__qualname__Ú__doc__Úauto_createdÚconcreteÚeditableÚis_relationÚnullÚempty_strings_allowedr   r   r   r   Úpropertyr    r&   r(   r*   r,   r+   r-   r/   r2   r4   r5   r6   r<   r=   rB   rD   rJ   r   rW   r   r]   r_   r`   rd   rh   rl   r"   rm   r   r   r   r   r	      sv    
ø











û



r	   c                       sX   e Zd ZdZ					d‡ fdd„	Z‡ f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   ©r?   r   r   r     s   ù

zManyToOneRel.__init__c                    s   t ƒ  ¡ }| dd ¡ |S )Nr(   )r{   rJ   rG   rH   r}   r   r   rJ   (  s   
zManyToOneRel.__getstate__c                    s   t ƒ j| jf S r   )r{   r=   rc   r   r}   r   r   r=   -  s   zManyToOneRel.identityc                 C   s*   | j j | j¡}|jst d| j ¡‚|S )zY
        Return the Field in the 'to' object to which this relationship is tied.
        zNo related field named '%s')r   r9   Ú	get_fieldrc   rs   r   ÚFieldDoesNotExist)r   r
   r   r   r   Úget_related_field1  s   ÿzManyToOneRel.get_related_fieldc                 C   s   | j p| jjjj| _ d S r   )rc   r   r9   rK   r   r   r   r   r   rd   <  s   zManyToOneRel.set_field_namern   )r8   ro   rp   rq   r   rJ   rx   r=   r€   rd   Ú__classcell__r   r   r}   r   ry     s    ÷ry   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 )Nrz   F)r{   r   r   r|   r}   r   r   r   H  s   ø
zOneToOneRel.__init__rn   )r8   ro   rp   rq   r   r�   r   r   r}   r   r‚   @  s    ÷r‚   c                       sH   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
           
         sR   t ƒ j|||||d� |r|	stdƒ‚|| _|r|s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)r{   r   Ú
ValueErrorÚthroughÚthrough_fieldsr   Údb_constraint)
r   r
   r   r   r   r   r   r…   r†   r‡   r}   r   r   r   i  s   û
zManyToManyRel.__init__c                    s   t ƒ j| jt| jƒ| jf S r   )r{   r=   r…   r   r†   r‡   r   r}   r   r   r=   ˆ  s
   ýzManyToManyRel.identityc                 C   sV   | j j}| jr| | jd ¡}n|jD ]}t|ddƒ}|r%|j| jkr% nq|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…   r9   r†   r~   ÚfieldsÚgetattrr   Úforeign_related_fields)r   rg   r
   Úrelr   r   r   r€   �  s   
€
zManyToManyRel.get_related_field)NNNTNNT)	r8   ro   rp   rq   r   rx   r=   r€   r�   r   r   r}   r   rƒ   a  s    örƒ   )rq   rZ   Údjango.corer   Údjango.utils.deprecationr   Údjango.utils.functionalr   Údjango.utils.hashabler   rf   r   Úmixinsr   r	   ry   r‚   rƒ   r   r   r   r   Ú<module>   s     l>!