File: //usr/lib/python3/dist-packages/django/db/migrations/operations/__pycache__/utils.cpython-310.pyc
o
3�a� � @ sP d dl mZ d dlmZ ddd�Zedd�Z ddd �Zddd�Zd
d� ZdS )� )�
namedtuple)�RECURSIVE_RELATIONSHIP_CONSTANTNc C s� t | t�r9| tkr|du s|du rtd��||fS d| v r+| �dd�\}}||�� fS |du r3td��|| �� fS | jj| jjfS )z�
Turn a model class or model reference string and return a model tuple.
app_label and model_name are used to resolve the scope of recursive and
unscoped model relationship.
NzMapp_label and model_name must be provided to resolve recursive relationships.�.� zCapp_label must be provided to resolve unscoped model relationships.) �
isinstance�strr � TypeError�split�lower�_meta� app_label�
model_name)�modelr r
� r �G/usr/lib/python3/dist-packages/django/db/migrations/operations/utils.py�resolve_relation s
��r �FieldReferencez
to throughc C s� |j }|sdS d}d}t|jg| �R � |kr7t|dd�}|du s3|du s3d|v r/|du s3|js3||v r7||f}t|dd�} | r\t| g| �R � |kr\|j}
|du sX|
du sX||
v r\||
f}|sb|sbdS t||�S )at
Return either False or a FieldReference if `field` references provided
context.
False positives can be returned if `reference_field_name` is provided
without `reference_field` because of the introspection limitation it
incurs. This should not be an issue when this function is used to determine
whether or not an optimization can take place.
FN� to_fields�through)�remote_fieldr r �getattr�primary_key�through_fieldsr )�model_tuple�field�reference_model_tuple�reference_field_name�reference_fieldr �
references_to�references_throughr r r r r r �field_references$ s,
r r c c sT � | j �� D ]!\}}|j�� D ]\}}t|||g|�R � }|r&||||fV qqdS )z�
Generator of (model_state, name, field, reference) referencing
provided context.
If field_tuple is provided only references to this particular field of
model_tuple will be generated.
N)�models�items�fieldsr )�stater �field_tuple�state_model_tuple�model_state�namer � referencer r r �get_referencesU s ����r* c C s t t| ||�d�duS )z?Return whether `field_tuple` is referenced by any state models.N)�nextr* )r$ r r% r r r �field_is_referencedd s r, )NN)r ) �collectionsr �django.db.models.fields.relatedr r r r r* r, r r r r �<module> s
�
1