o
    {,hl2                     @   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                   @   sj  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%ed8d9 Z&dCd:d;Z'dCd<d=Z(ed>d? Z)e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/rh/venv/lib/python3.10/site-packages/django/db/models/fields/reverse_related.py__init__*   s   

zForeignObjectRel.__init__c                 C   s   t | jo| jd dkS )z$Should the related object be hidden?+)boolr   r   r   r   r   hiddenC   s   zForeignObjectRel.hiddenc                 C   
   | j  S N)r
   r   r   r   r   r   nameH   s   
zForeignObjectRel.namec                 C      | j S r   )r
   r   r   r   r   remote_fieldL   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   r   z1Can't use target_field for multicolumn relations.r   )
path_infostarget_fieldslenr   
FieldError)r   r#   r   r   r   target_fieldP   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*   f      zForeignObjectRel.many_to_manyc                 C   r)   r   )r
   one_to_manyr   r   r   r   many_to_onej   r+   zForeignObjectRel.many_to_onec                 C   r)   r   )r
   r-   r   r   r   r   r,   n   r+   zForeignObjectRel.one_to_manyc                 C   r)   r   )r
   
one_to_oner   r   r   r   r.   r   r+   zForeignObjectRel.one_to_onec                 C      | j |S r   )r
   
get_lookup)r   lookup_namer   r   r   r0   v      zForeignObjectRel.get_lookupc                 C   r   r   )r
   get_lookupsr   r   r   r   r3   y      
zForeignObjectRel.get_lookupsc                 C   r/   r   )r
   get_transform)r   r   r   r   r   r5   |   r2   zForeignObjectRel.get_transformc                 C   r   r   )r
   get_internal_typer   r   r   r   r6      r4   z"ForeignObjectRel.get_internal_typec                 C   r)   r   )r
   db_typer   r   r   r   r7      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__   r4   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dtdd | j S )NzWForeignObjectRel.get_joining_columns() is deprecated. Use get_joining_fields() instead.   )
stacklevel)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   r4   z#ForeignObjectRel.get_joining_fieldsc                 C   s   | j ||S r   )r
   get_extra_restriction)r   alias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_namer   r   r   r   set_field_name   s   
zForeignObjectRel.set_field_namec                 C      |   S r   )get_accessor_namer   r   r   r   accessor_name   r+   zForeignObjectRel.accessor_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 )r:   r(   r   r   r   r   r<   )r   r   optsr   r   r   rg      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   rf   r   )ro   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   
cache_name   s   zForeignObjectRel.cache_nameNNNFNr   )+r9   
__module____qualname____doc__auto_createdconcreteeditableis_relationnullempty_strings_allowedr   r   r   r   propertyr!   r&   r(   r*   r-   r,   r.   r0   r3   r5   r6   r7   r=   r>   rC   rE   rK   r   rX   r^   r`   ra   re   rh   rg   ro   r"   rp   r   r   r   r   r	      sz    












	




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   rd   	r   r
   r   rd   r   r   r   r   r   r@   r   r   r     s   

zManyToOneRel.__init__c                    s   t   }|dd  |S )Nr(   )r~   rK   rH   rI   r   r   r   rK   +  s   
zManyToOneRel.__getstate__c                    s   t  j| jf S r   )r~   r>   rd   r   r   r   r   r>   0  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   r:   	get_fieldrd   rv   r   FieldDoesNotExist)r   r
   r   r   r   get_related_field4  s   zManyToOneRel.get_related_fieldc                 C   s   | j p| jjjj| _ d S r   )rd   r   r:   rL   r   r   r   r   r   re   ?  s   zManyToOneRel.set_field_namerq   )r9   rr   rs   rt   r   rK   r{   r>   r   re   __classcell__r   r   r   r   r|     s    r|   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 )Nr}   F)r~   r   r   r   r   r   r   r   K  s   
zOneToOneRel.__init__rq   )r9   rr   rs   rt   r   r   r   r   r   r   r   C  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   l  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   r:   r   r   fieldsgetattrr   foreign_related_fields)r   rk   r
   relr   r   r   r     s   

zManyToManyRel.get_related_field)NNNTNNT)	r9   rr   rs   rt   r   r{   r>   r   r   r   r   r   r   r   d  s    r   )rt   r[   django.corer   django.utils.deprecationr   django.utils.functionalr   django.utils.hashabler   rj   r   mixinsr   r	   r|   r   r   r   r   r   r   <module>   s     o>!