
    gR2                         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e      Z G d de      Z G d de      Z G d de      Zy)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                      e Zd ZdZdZdZdZdZdZdZ		 	 	 	 	 d$dZ
ed        Zed        Zed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zd Zd Zd Zd Zed        Zd Zed        Zd Zd Zd Zde ddfdZ!d Z"d Z#d Z$d Z%ed        Z&d%d Z'd%d!Z(ed"        Z)ed#        Z*y)&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                     || _         || _        || _        || _        |i n|| _        || _        || _        d| _        d| _        y )NFT)	fieldmodelrelated_namerelated_query_namelimit_choices_toparent_link	on_deletesymmetricalmultiple)selfr   tor   r   r   r   r   s           /var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/db/models/fields/reverse_related.py__init__zForeignObjectRel.__init__*   sP     

("4&6&>DT&"     c                 T    t        | j                        xr | j                  d   dk(  S )z$Should the related object be hidden?+)boolr   r   s    r   hiddenzForeignObjectRel.hiddenC   s*     D%%&G4+<+<R+@C+GGr   c                 6    | j                   j                         S N)r   r   r   s    r   namezForeignObjectRel.nameH   s    zz,,..r   c                     | j                   S r"   )r   r   s    r   remote_fieldzForeignObjectRel.remote_fieldL   s    zzr   c                     | j                   d   j                  }t        |      dkD  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   r   z1Can't use target_field for multicolumn relations.r   )
path_infostarget_fieldslenr   
FieldError)r   r(   s     r   target_fieldzForeignObjectRel.target_fieldP   sH     +99}!''C  Qr   c                 p    | 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   s    r   related_modelzForeignObjectRel.related_model]   s3    zz #  zzr   c                 .    | j                   j                  S r"   )r   many_to_manyr   s    r   r0   zForeignObjectRel.many_to_manyf   s    zz&&&r   c                 .    | j                   j                  S r"   )r   one_to_manyr   s    r   many_to_onezForeignObjectRel.many_to_onej       zz%%%r   c                 .    | j                   j                  S r"   )r   r3   r   s    r   r2   zForeignObjectRel.one_to_manyn   r4   r   c                 .    | j                   j                  S r"   )r   
one_to_oner   s    r   r7   zForeignObjectRel.one_to_oner   s    zz$$$r   c                 8    | j                   j                  |      S r"   )r   
get_lookup)r   lookup_names     r   r9   zForeignObjectRel.get_lookupv   s    zz$$[11r   c                 6    | j                   j                         S r"   )r   get_lookupsr   s    r   r<   zForeignObjectRel.get_lookupsy   s    zz%%''r   c                 8    | j                   j                  |      S r"   )r   get_transform)r   r#   s     r   r>   zForeignObjectRel.get_transform|   s    zz''--r   c                 6    | j                   j                         S r"   )r   get_internal_typer   s    r   r@   z"ForeignObjectRel.get_internal_type   s    zz++--r   c                 .    | j                   j                  S r"   )r   db_typer   s    r   rB   zForeignObjectRel.db_type   s    zz!!!r   c                     dt        |       j                  d| j                  j                  j                  d| j                  j                  j
                  dS )N<z: .>)type__name__r.   _meta	app_label
model_namer   s    r   __repr__zForeignObjectRel.__repr__   sC    J$$..$$//
 	
r   c           	          | j                   | j                  | j                  | j                  t	        | j
                        | j                  | j                  | j                  | j                  f	S r"   )
r   r   r   r   r   r   r   r   r   r   r   s    r   identityzForeignObjectRel.identity   s\     JJJJ##$//0NNMM

 
	
r   c                 l    t        || j                        st        S | j                  |j                  k(  S r"   )
isinstance	__class__NotImplementedrN   )r   others     r   __eq__zForeignObjectRel.__eq__   s)    %0!!}}..r   c                 ,    t        | j                        S r"   )hashrN   r   s    r   __hash__zForeignObjectRel.__hash__   s    DMM""r   c                 ^    | j                   j                         }|j                  dd        |S )Nr'   )__dict__copypop)r   states     r   __getstate__zForeignObjectRel.__getstate__   s)    ""$ 			,%r    c                     |xs | j                   }| j                  j                  j                  |      }|r |j                  | }|r|ng |D cg c]  }|j
                  t        |      f c}z   S c c}w )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.
        )r   r.   _default_managercomplex_filterorder_bypkstr)r   include_blankblank_choicer   orderingqsxs          r   get_choiceszForeignObjectRel.get_choices   su     ,Dt/D/D00??@PQh'B -2RT9URTQ144Q.RT9UUU9Us   A3c                 j    t        j                  dt               | j                  j	                         S )NzWForeignObjectRel.get_joining_columns() is deprecated. Use get_joining_fields() instead.)warningswarnr   r   get_reverse_joining_columnsr   s    r   get_joining_columnsz$ForeignObjectRel.get_joining_columns   s+    ,$	

 zz5577r   c                 6    | j                   j                         S r"   )r   get_reverse_joining_fieldsr   s    r   get_joining_fieldsz#ForeignObjectRel.get_joining_fields   s    zz4466r   c                 :    | j                   j                  ||      S r"   )r   get_extra_restriction)r   aliasrelated_aliass      r   rt   z&ForeignObjectRel.get_extra_restriction   s    zz//uEEr   c                     d| _         y)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   s    r   set_field_namezForeignObjectRel.set_field_name   s     r   c                 "    | j                         S r"   )get_accessor_namer   s    r   accessor_namezForeignObjectRel.accessor_name   s    %%''r   c                 (   |r|j                   n| j                  j                   }|xs | j                  }| j                  r| j                  r|| j                  k(  ry | j
                  r| j
                  S |j                  | j                  rdz   S dz   S )N_set )rI   r.   r   r   r   r   rK   )r   r   optss      r   r{   z"ForeignObjectRel.get_accessor_name   s     $u{{););)A)A+++== ETZZ$7$$$DMM&BBrBBr   c                 h    |r| j                   j                  |      S | j                   j                  S r"   )r   get_reverse_path_inforeverse_path_infos)r   filtered_relations     r   get_path_infozForeignObjectRel.get_path_info   s+    ::334EFF::000r   c                 "    | j                         S r"   )r   r   s    r   r'   zForeignObjectRel.path_infos   s    !!##r   c                     | j                   S )z
        Return the name of the cache key to use for storing an instance of the
        forward model on the reverse model.
        )r|   r   s    r   
cache_namezForeignObjectRel.cache_name   s     !!!r   NNNFNr"   )+rH   
__module____qualname____doc__auto_createdconcreteeditableis_relationnullempty_strings_allowedr   r   r    r#   propertyr%   r+   r.   r0   r3   r2   r7   r9   r<   r>   r@   rB   rL   rN   rT   rW   r]   r   rj   ro   rr   rt   ry   r|   r{   r   r'   r   r^   r   r   r   r      s    LHHK D! 2 H H / /   
  
      ' ' & & & & % %2(.. " "
 
 
/
#
 &V(87F ( (C$1 $ $ " "r   r   c                   X     e Zd ZdZ	 	 	 	 	 d fd	Z fdZe fd       Zd Zd Z	 x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.
    c	           	      @    t         	|   |||||||       || _        y )Nr   r   r   r   r   )superr   rx   
r   r   r   rx   r   r   r   r   r   rQ   s
            r   r   zManyToOneRel.__init__  s5     	%1-# 	 	
 %r   c                 H    t         |          }|j                  dd        |S )Nr.   )r   r]   r[   )r   r\   rQ   s     r   r]   zManyToOneRel.__getstate__*  s#    $&		/4(r   c                 4    t         |   | j                  fz   S r"   )r   rN   rx   r   rQ   s    r   rN   zManyToOneRel.identity/  s    w4??"444r   c                     | j                   j                  j                  | j                        }|j                  s"t        j                  d| j                  z        |S )zY
        Return the Field in the 'to' object to which this relationship is tied.
        zNo related field named '%s')r   rI   	get_fieldrx   r   r   FieldDoesNotExist)r   r   s     r   get_related_fieldzManyToOneRel.get_related_field3  sO     

  **4??;~~..-?  r   c                 ~    | j                   xs* | j                  j                  j                  j                  | _         y r"   )rx   r   rI   rc   r#   r   s    r   ry   zManyToOneRel.set_field_name>  s(    //ETZZ-=-=-@-@-E-Er   r   )rH   r   r   r   r   r]   r   rN   r   ry   __classcell__rQ   s   @r   r   r     sB    & %.
 5 5	Fr   r   c                   .     e Zd ZdZ	 	 	 	 	 d fd	Z x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.
    c	           
      B    t         	|   ||||||||       d| _        y )Nr   F)r   r   r   r   s
            r   r   zOneToOneRel.__init__J  s8     	%1-# 	 		
 r   r   )rH   r   r   r   r   r   r   s   @r   r   r   B  s#      r   r   c                   L     e Zd ZdZ	 	 	 	 	 	 	 d fd	Ze fd       Zd Z x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.
    c
                     t         
|   |||||       |r|	st        d      || _        |r|st        d      || _        || _        |	| _        y )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   rQ   s             r   r   zManyToManyRel.__init__k  si     	%1- 	 	
 =STT'TUU,&*r   c                 r    t         |   | j                  t        | j                        | j
                  fz   S r"   )r   rN   r   r   r   r   r   s    r   rN   zManyToManyRel.identity  s8    wLL$--.#
 
 	
r   c                    | j                   j                  }| j                  r|j                  | j                  d         }n<|j                  D ]-  }t        |dd      }|s|j                  | j                  k(  s- n 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   rI   r   r   fieldsgetattrr   foreign_related_fields)r   r   r   rels       r   r   zManyToManyRel.get_related_field  sy    
 ||!!NN4#6#6q#9:Ee^T:399

2 % ++A..r   )NNNTNNT)	rH   r   r   r   r   r   rN   r   r   r   s   @r   r   r   c  s=     +> 
 
/r   r   )r   rl   django.corer   django.utils.deprecationr   django.utils.functionalr   django.utils.hashabler   r   r   mixinsr	   r   r   r   r   r^   r   r   <module>r      sZ   	  " = 3 /  #j" j"Z;F# ;F|, B</$ </r   