
     h0                         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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                      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)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                     || _         || _        || _        || _        |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   s           f/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/django/db/models/fields/reverse_related.py__init__zForeignObjectRel.__init__'   sV     

("4&6&>DT&"     c                 *    |                                  S N)	is_hiddenr   s    r   hiddenzForeignObjectRel.hidden@   s    ~~r   c                 4    | j                                         S r   )r   r   r   s    r   namezForeignObjectRel.nameD   s    z,,...r   c                     | j         S r   )r   r   s    r   remote_fieldzForeignObjectRel.remote_fieldH   s
    zr   c                     | 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   )
path_infostarget_fieldslenr   
FieldError)r   r&   s     r   target_fieldzForeignObjectRel.target_fieldL   sK     +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    z 	 #   zr   c                     | j         j        S r   )r   many_to_manyr   s    r   r.   zForeignObjectRel.many_to_manyb   s    z&&r   c                     | j         j        S r   )r   one_to_manyr   s    r   many_to_onezForeignObjectRel.many_to_onef       z%%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    z$$r   c                 6    | j                             |          S r   )r   
get_lookup)r   lookup_names     r   r7   zForeignObjectRel.get_lookupr   s    z$$[111r   c                 4    | j                                         S r   )r   get_lookupsr   s    r   r:   zForeignObjectRel.get_lookupsu   s    z%%'''r   c                 6    | j                             |          S r   )r   get_transform)r   r    s     r   r<   zForeignObjectRel.get_transformx   s    z''---r   c                 4    | j                                         S r   )r   get_internal_typer   s    r   r>   z"ForeignObjectRel.get_internal_type{   s    z++---r   c                     | j         j        S r   )r   db_typer   s    r   r@   zForeignObjectRel.db_type~   s    z!!r   c                 z    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__   sD     JJ$...$///
 	
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   sH     JJ#$/00NM

 
	
r   c                 Z    t          || j                  st          S | j        |j        k    S r   )
isinstance	__class__NotImplementedrL   )r   others     r   __eq__zForeignObjectRel.__eq__   s+    %00 	"!!}..r   c                 *    t          | j                  S r   )hashrL   r   s    r   __hash__zForeignObjectRel.__hash__   s    DM"""r   c                 d    | j                                         }|                    dd            |S )Nr%   )__dict__copypop)r   states     r   __getstate__zForeignObjectRel.__getstate__   s0    ""$$ 			,%%%r    c                     |p| j         }| j        j                            |          }|r
 |j        | }|r|ng d |D             z   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                 :    g | ]}|j         t          |          fS r\   )pkstr).0xs     r   
<listcomp>z0ForeignObjectRel.get_choices.<locals>.<listcomp>   s$    9U9U9UQ14Q.9U9U9Ur   )r   r,   _default_managercomplex_filterorder_by)r   include_blankblank_choicer   orderingqss         r   get_choiceszForeignObjectRel.get_choices   sf     ,Dt/D0??@PQQ 	(h'B -529U9URT9U9U9UUUr   c                 L    t          | j                  o| 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                 4    | j                                         S r   )r   get_reverse_joining_columnsr   s    r   get_joining_columnsz$ForeignObjectRel.get_joining_columns   s    z55777r   c                 8    | j                             ||          S r   )r   get_extra_restriction)r   aliasrelated_aliass      r   rs   z&ForeignObjectRel.get_extra_restriction   s    z//uEEEr   c                     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   s    r   set_field_namezForeignObjectRel.set_field_name   s     r   c                     |r|j         n| j        j         }|p| j        }| j        r| j        r|| j        k    rd S | j        r| j        S |j        | j        rdndz   S )N_set )rG   r,   r   r   r   r   rI   )r   r   optss      r   get_accessor_namez"ForeignObjectRel.get_accessor_name   s{     $Au{{);)A++= 	  ETZ$7$7t 	%$$DM"A&&rBBr   c                 R    |r| 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,     	1:334EFFF:00r   c                 *    |                                  S r   )r   r   s    r   r%   zForeignObjectRel.path_infos   s    !!###r   c                 *    |                                  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   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   rk   r   rq   rs   rx   r}   r   r%   r   r\   r   r   r
   r
      s         LHHK D!    2     _  / / _/   X 
  
  X
      _  ' ' _' & & _& & & _& % % _%2 2 2( ( (. . .. . . " " X"
 
 
 
 
 X
/ / /
# # #
 
 
 &V V V V(H H H8 8 8F F F  C C C C$1 1 1 1 $ $ _$( ( ( ( (r   r
   c                   ^     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.
    NFc	           	      f    t                                          |||||||           || _        d S )Nr   r   r   r   r   )superr   rw   
r   r   r   rw   r   r   r   r   r   rO   s
            r   r   zManyToOneRel.__init__  sH     	%1-# 	 	
 	
 	
 %r   c                 t    t                                                      }|                    dd            |S )Nr,   )r   r[   rY   )r   rZ   rO   s     r   r[   zManyToOneRel.__getstate__  s1    $$&&		/4(((r   c                 <    t                      j        | j        fz   S r   )r   rL   rw   r   rO   s    r   rL   zManyToOneRel.identity"  s    ww4?"444r   c                     | 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_fieldrw   r   r   FieldDoesNotExist)r   r   s     r   get_related_fieldzManyToOneRel.get_related_field&  sN     
 **4?;;~ 	.-?   r   c                 J    | j         p| j        j        j        j        | _         d S r   )rw   r   rG   r_   r    r   s    r   rx   zManyToOneRel.set_field_name1  s    /ETZ-=-@-Er   r   )rF   r   r   r   r   r[   r   rL   r   rx   __classcell__rO   s   @r   r   r      s         & % % % % % %.    
 5 5 5 5 X5	 	 	F F F F F F 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.
    NFc	           
      h    t                                          ||||||||           d| _        d S )Nr   F)r   r   r   r   s
            r   r   zOneToOneRel.__init__=  sK     	%1-# 	 		
 		
 		
 r   r   )rF   r   r   r   r   r   r   s   @r   r   r   5  sX                   r   r   c                   R     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.
    NTc
                     t                                          |||||           |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   rO   s             r   r   zManyToManyRel.__init__^  s     	%1- 	 	
 	
 	
  	U= 	USTTT 	V' 	VTUUU,&*r   c                 n    t                      j        | j        t          | j                  | j        fz   S r   )r   rL   r   r   r   r   r   s    r   rL   zManyToManyRel.identity}  s5    wwL$-..#
 
 	
r   c                     | j         j        }| j        r!|                    | j        d                   }n/|j        D ]'}t          |dd          }|r|j        | j        k    r 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   r|   r   rels       r   r   zManyToManyRel.get_related_field  s    
 |! 	NN4#6q#9::EE  e^T:: 39
22E+A..r   )NNNTNNT)	rF   r   r   r   r   r   rL   r   r   r   s   @r   r   r   V  s          + + + + + +> 
 
 
 
 X
/ / / / / / /r   r   N)r   django.corer   django.utils.functionalr   django.utils.hashabler   r{   r   mixinsr   r
   r   r   r   r\   r   r   <module>r      s2  	 	 # " " " " " 3 3 3 3 3 3 / / / / / /       # # # # # #`( `( `( `( `( `( `( `(F;F ;F ;F ;F ;F# ;F ;F ;F|    ,   B</ </ </ </ </$ </ </ </ </ </r   