o
    wvXj}  ã                   @   s|   d Z ddlmZmZ edg d¢ƒZedg d¢ƒZdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )zý
Helper function for returning the field information that is associated
with a model class. This includes returning all the forward and reverse
relationships and their associated metadata.

Usage: `get_field_info(model)` returns a `FieldInfo` instance.
é    )ÚOrderedDictÚ
namedtupleÚFieldResult)ÚpkÚfieldsÚforward_relationsÚreverse_relationsÚfields_and_pkÚ	relationsÚRelationInfo©Úmodel_fieldÚrelated_modelÚto_manyÚto_fieldÚhas_through_modelÚreversec                 C   sP   | j jj }t|ƒ}t|ƒ}t|ƒ}t|ƒ}t||ƒ}t||ƒ}t||||||ƒS )zÏ
    Given a model class, returns a `FieldInfo` instance, which is a
    `namedtuple`, containing metadata about the various field types on the model
    including information about their relationships.
    )	Ú_metaÚconcrete_modelÚ_get_pkÚ_get_fieldsÚ_get_forward_relationshipsÚ_get_reverse_relationshipsÚ_merge_fields_and_pkÚ_merge_relationshipsÚ	FieldInfo)ÚmodelÚoptsr   r   r   r   r	   Úrelationships© r   ú\/var/www/html/myproject/venv/lib/python3.10/site-packages/rest_framework/utils/model_meta.pyÚget_field_info   s   



ÿr!   c                 C   s6   | j }|j}|r|jr|jjjj }|j}|r|js|S ©N)r   Úremote_fieldÚparent_linkr   r   )r   r   Úrelr   r   r    r   0   s   

ýr   c                 C   s*   t ƒ }dd„ | jD ƒD ]}|||j< q|S )Nc                 S   s   g | ]
}|j r|js|‘qS r   ©Ú	serializer#   ©Ú.0Úfieldr   r   r    Ú
<listcomp>>   ó    z_get_fields.<locals>.<listcomp>)r   r   Úname)r   r   r*   r   r   r    r   <   s   r   c                 C   s   t | dd ƒo
| jd S )NÚ	to_fieldsr   )Úgetattrr.   )r*   r   r   r    Ú_get_to_fieldD   s   r0   c              	   C   s€   t ƒ }dd„ | jD ƒD ]}t||jjdt|ƒddd�||j< qdd„ | jD ƒD ]}t||jjdd|jjj	j
 dd�||j< q'|S )úD
    Returns an `OrderedDict` of field names to `RelationInfo`.
    c                 S   s   g | ]
}|j r|jr|‘qS r   r&   r(   r   r   r    r+   M   r,   z._get_forward_relationships.<locals>.<listcomp>Fr   c                 S   s   g | ]}|j r|‘qS r   )r'   r(   r   r   r    r+   X   s    TN)r   r   r   r#   r   r0   r-   Úmany_to_manyÚthroughr   Úauto_created)r   r   r*   r   r   r    r   H   s(   ú
÷r   c              
   C   s®   t ƒ }dd„ | jD ƒ}|D ]}| ¡ }td|j|jjjt|jƒddd�||< qdd„ | jD ƒ}|D ]#}| ¡ }td|jddt	|jjddƒduoN|jjj
jj dd�||< q1|S )	r1   c                 S   s   g | ]}|j js|‘qS r   ©r*   r2   ©r)   Úrr   r   r    r+   m   ó    z._get_reverse_relationships.<locals>.<listcomp>NFTr   c                 S   s   g | ]}|j jr|‘qS r   r5   r6   r   r   r    r+   z   r8   r3   )r   Úrelated_objectsÚget_accessor_namer   r   r*   r#   Úmultipler0   r/   r3   r   r4   )r   r   Úall_related_objectsÚrelationÚaccessor_nameÚ all_related_many_to_many_objectsr   r   r    r   h   s2   ú
ör   c                 C   s&   t ƒ }| |d< | || j< | |¡ |S )Nr   )r   r-   Úupdate)r   r   r	   r   r   r    r   �   s
   

r   c                 C   s   t t|  ¡ ƒt| ¡ ƒ ƒS r"   )r   ÚlistÚitems)r   r   r   r   r    r   –   s
   

ÿÿr   c                 C   s   t | dƒot | jdƒo| jjS )z_
    Given a model class, returns a boolean True if it is abstract and False if it is not.
    r   Úabstract)Úhasattrr   rC   )r   r   r   r    Úis_abstract_model�   s   rE   N)Ú__doc__Úcollectionsr   r   r   r   r!   r   r   r0   r   r   r   r   rE   r   r   r   r    Ú<module>   s    	
 %	