
    Hwg0                         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	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.
    )
exceptions)cached_property)make_hashable   )BLANK_CHOICE_DASH)FieldCacheMixinc                   h   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%d$dZ&d$d Z'ed!        Z(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/horilla/myenv/lib/python3.12/site-packages/django/db/models/fields/reverse_related.py__init__zForeignObjectRel.__init__'   sP     

("4&6&>DT&"     c                 "    | j                         S N)	is_hiddenr   s    r   hiddenzForeignObjectRel.hidden@   s    ~~r   c                 6    | j                   j                         S r   )r   r   r   s    r   namezForeignObjectRel.nameD   s    zz,,..r   c                     | j                   S r   )r   r   s    r   remote_fieldzForeignObjectRel.remote_fieldH   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   z1Can't use target_field for multicolumn relations.r   )
path_infostarget_fieldslenr   
FieldError)r   r&   s     r   target_fieldzForeignObjectRel.target_fieldL   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_modelY   s3    zz #  zzr   c                 .    | j                   j                  S r   )r   many_to_manyr   s    r   r.   zForeignObjectRel.many_to_manyb   s    zz&&&r   c                 .    | j                   j                  S r   )r   one_to_manyr   s    r   many_to_onezForeignObjectRel.many_to_onef       zz%%%r   c                 .    | j                   j                  S r   )r   r1   r   s    r   r0   zForeignObjectRel.one_to_manyj   r2   r   c                 .    | j                   j                  S r   )r   
one_to_oner   s    r   r5   zForeignObjectRel.one_to_onen   s    zz$$$r   c                 8    | j                   j                  |      S r   )r   
get_lookup)r   lookup_names     r   r7   zForeignObjectRel.get_lookupr   s    zz$$[11r   c                 6    | j                   j                         S r   )r   get_lookupsr   s    r   r:   zForeignObjectRel.get_lookupsu   s    zz%%''r   c                 8    | j                   j                  |      S r   )r   get_transform)r   r    s     r   r<   zForeignObjectRel.get_transformx   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   r@   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__NotImplementedrL   )r   others     r   __eq__zForeignObjectRel.__eq__   s)    %0!!}}..r   c                 ,    t        | j                        S r   )hashrL   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   so     ,Dt/D/D00??@PQh'B -2RT9UQ144Q.9UUU9Us   A3c                 T    t        | j                        xr | j                  d   dk(  S )z$Should the related object be hidden?r$   +)boolr   r   s    r   r   zForeignObjectRel.is_hidden   s(    D%%&G4+<+<R+@C+GGr   c                 6    | j                   j                         S r   )r   get_reverse_joining_columnsr   s    r   get_joining_columnsz$ForeignObjectRel.get_joining_columns   s    zz5577r   c                 :    | j                   j                  ||      S r   )r   get_extra_restriction)r   aliasrelated_aliass      r   rp   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                 (   |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 )rG   r,   r   r   r   r   rI   )r   r   optss      r   get_accessor_namez"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.
        )rz   r   s    r   get_cache_namezForeignObjectRel.get_cache_name   s    
 %%''r   NNNFNr   )*rF   
__module____qualname____doc__auto_createdconcreteeditableis_relationnullempty_strings_allowedr   r   r   r    propertyr"   r)   r,   r.   r1   r0   r5   r7   r:   r<   r>   r@   rJ   rL   rR   rU   r[   r   rh   r   rn   rp   ru   rz   r   r%   r   r\   r   r   r
   r
      s    LHHK D! 2     / /   
  
      ' ' & & & & % %2(.. " "
 
 
/
#
 &V(H8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   rt   
r   r   r   rt   r   r   r   r   r   rO   s
            r   r   zManyToOneRel.__init__  s5     	%1-# 	 	
 %r   c                 H    t         |          }|j                  dd        |S )Nr,   )r   r[   rY   )r   rZ   rO   s     r   r[   zManyToOneRel.__getstate__  s#    $&		/4(r   c                 4    t         |   | j                  fz   S r   )r   rL   rt   r   rO   s    r   rL   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   rG   	get_fieldrt   r   r   FieldDoesNotExist)r   r   s     r   get_related_fieldzManyToOneRel.get_related_field&  sO     

  **4??;~~..-?  r   c                 ~    | j                   xs* | j                  j                  j                  j                  | _         y r   )rt   r   rG   ra   r    r   s    r   ru   zManyToOneRel.set_field_name1  s(    //ETZZ-=-=-@-@-E-Er   r   )rF   r   r   r   r   r[   r   rL   r   ru   __classcell__rO   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__=  s8     	%1-# 	 		
 r   r   )rF   r   r   r   r   r   r   s   @r   r   r   5  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   rO   s             r   r   zManyToManyRel.__init__^  si     	%1- 	 	
 =STT'TUU,&*r   c                 r    t         |   | j                  t        | j                        | j
                  fz   S r   )r   rL   r   r   r   r   r   s    r   rL   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   rG   r   r   fieldsgetattrr   foreign_related_fields)r   ry   r   rels       r   r   zManyToManyRel.get_related_field  s~    
 ||!!NN4#6#6q#9:E e^T:399

2 ++A..r   )NNNTNNT)	rF   r   r   r   r   r   rL   r   r   r   s   @r   r   r   V  s=     +> 
 
/r   r   N)r   django.corer   django.utils.functionalr   django.utils.hashabler   rx   r   mixinsr   r
   r   r   r   r\   r   r   <module>r      sT   	 # 3 /  #`( `(F;F# ;F|, B</$ </r   