o
    ^"<f                     @   sP   d dl mZ d dlmZ dddZeddZ		ddd	ZdddZdd ZdS )    )
namedtuple)RECURSIVE_RELATIONSHIP_CONSTANTNc                 C   s   t | tr9| tkr|du s|du rtd||fS d| v r+| dd\}}|| fS |du r3td||  fS | jj| jjfS )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   \/var/www/html/kck/venv/lib/python3.10/site-packages/django/db/migrations/operations/utils.pyresolve_relation   s    
r   FieldReferencez
to throughc                 C   s   |j }|sdS d}d}t|jg| R  |kr7t|dd}|du s3|du s3d|v r/|du s3|js3||v r7||f}t|dd}	|	r\t|	g| R  |kr\|j}
|du sX|
du sX||
v r\||
f}|sb|sbdS 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&||||fV  qqdS )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duS )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